By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,835 Members | 1,391 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,835 IT Pros & Developers. It's quick & easy.

Using a user control within a master page

P: n/a
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!
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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...

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Cirene" <ci****@nowhere.comwrote in message news:%2****************@TK2MSFTNGP02.phx.gbl...
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!

Jun 27 '08 #2

P: n/a
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.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
"Cirene" <ci****@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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!
Jun 27 '08 #3

P: n/a
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.

"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:e1**************@TK2MSFTNGP03.phx.gbl...
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...

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Cirene" <ci****@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>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!


Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.