Using a user control within a master page

C

Cirene

When you set the value of a user control in a master page, do you have to
reference it differently? Also, do they have to be given different names in
the templates?

For example, this is what I have....
(uc1 is a user control I defined)

MasterPage.master
-- FormView#FormView1
--<EditItemTemplate>
--<table><tr><td>
-- uc1:ucTimeSelect ID="ucTime1"
--<ItemTemplate>
--<table><tr><td>
-- uc1:ucTimeSelect ID="ucTime1"
--<InsertItemTemplate>
--<table><tr><td>
-- uc1:ucTimeSelect ID="ucTime1"

Note that all the user controls have the same name.

In my code, when I switch modes in my formview I am trying to call a
function SetTime in my uc. It seems to work because I check the value
before & after. But it doesn't visually appear on the screen. Here's the
different ways I have tried...

1. CType(FormView1.FindControl("ucTime1"),
common_ucTimeSelect).SetTime(MyTime)
2.
CType(FormView1.Controls(0).Controls(1).Controls(0).FindControl("ucTime1"),
common_ucTimeSelect).SetTime(MyTime)

I check the value of the user control and the time IS set correctly, but
it's doesn't appear set on the screen.

Can you help me out?

Thanks!
 
J

Juan T. Llibre

To add a web user control to a master page, you must register the control

<%@ Register TagPrefix="uc1" TagName="ucTimeSelect" Src="~/ucTimeSelect.ascx" %>
-- FormView#FormView1
--<EditItemTemplate>
--<table><tr><td>
<uic1:ucTimeSelect id="ucTime1" runat="server" />

etc...
 
C

Cowboy \(Gregory A. Beamer\)

To follow up on Juan's post, the reason user controls are tricky in a master
page is the master page is, underneath the hood, a user control. I know it
does not feel this way when you design with it, but it is.
 
C

Cirene

I didn't want to add the uc to a master page. I wanted to add it to a page
that is based on the master page.

And, I did add the register at the top of the page already. :)

It shows up fine. It's just that when some values are set (via code) it
looks like it took (when debugging) but when the page shows up it doesn't
reflect the changes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,795
Messages
2,569,644
Members
45,357
Latest member
RuthEsteve

Latest Threads

Top