Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2008

Tip: Looking for answers? Try searching our database.

Using a user control within a master page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cirene - 19 May 2008 13:50 GMT
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!
Juan T. Llibre - 19 May 2008 14:17 GMT
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/
======================================
> 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?
[quoted text clipped - 28 lines]
>
> Thanks!
Cirene - 19 May 2008 15:45 GMT
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.

> To add a web user control to a master page, you must register the control
>
[quoted text clipped - 49 lines]
>>
>> Thanks!
Cowboy (Gregory A. Beamer) - 19 May 2008 15:29 GMT
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.

Signature

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!

*************************************************
> 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
[quoted text clipped - 34 lines]
>
> Thanks!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.