ASP.NET 1.0 and 1.1 ProfessionalFor advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5

Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .

Hello Everyone and thanks for your help in advance. I have a web site that is comprised of one web from, Default.aspx and multiple user controls that are loaded dynamically to alter the content of the page. I am trying to programmatically change the page title, however, it must be done from within the user controls. For example, when the control Details.ascx is loaded, I want the page tile to read something like "Contact Detail for John Doe". Obviously, the user control will have to pass the information back to the main page. I am not exactly sure how to do this. Any help would be greatly appreciated. Thanks.

All web controls contain the Page property. It references the containing page of the control. With it you can access anything on the instance of that page class.

- Modify your page's <title> tag to include runat="server" and an ID attribute (for example id="tagTitle"). This tag will be instantiated as an HtmlGenericControl.
- The <title> will also need an associate class field in the code behind for the page:

Protected tagTitle As System.Web.UI.HtmlControls.HtmlGenericControl

- Add a public property to your page class to expose the title tag's property that you need. We'll name it "PageTitle":

Public Property PageTitle() As String
Get
Return tagTitle.InnerHtml
End Get
Set(ByVal Value As String)
tagTitle.InnerHtml = Value
End Set
End Property

- Within your user control, you'll need to convert the Page property of the user control to the right page class in order to see the property you added. Here's the code you call within the user control:

CType(Me.Page, default).PageTitle = "My customized page title"

Important points:
- default is the class name of the ASPX. You may need to set this based on the actual class associated with the ASPX you use this on.
- If you do this on multiple user controls, the LAST one to make the call will get the final say about the page title.

Here is a sectionof an article that explains a slightly more complex concept that greatly simplifies this kind of operation when you have a situation that requires this type of coding on lots of pages and controls. It has some sample code that you can adapt to suit your specific need.

Peter
------------------------------------------------------
Work smarter, not harder.