locked
How to change the page(aspx) title from Usercontrol(ascx) the inside the page(aspx) (asp.net 1.1) ?? RRS feed

  • Question

  • User-412120464 posted

    Hi

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    I have user control(ascx) inside  the page(aspx) and from the code behind of that user control How can I change the page(aspx) title??

    <o:p> </o:p>

    Note : Please my Question about asp.net 1.1

    <o:p> </o:p>

    And thanks with my best regarding

    Fraas

    Friday, January 20, 2006 10:42 AM

All replies

  • User-2041805088 posted
    I'm having a little trouble understanding why you want to change the title of the aspx page from the ascx control when you can change the title directly in the aspx page. Please clarify.
    Friday, January 20, 2006 11:05 AM
  • User798903548 posted

    This question gets asked so many times that it amazes me.

    Basically you have to add a public property to the UserControl. Then you can get/set the value in the parent page. Example:

    In the User Control (ascx):
    Create a public property:
          private string m_ValueToPass = string.Empty;
          public string ValueToPass
          {
                get { return this.m_ValueToPass; }
                set { m_ValueToPass = value; }
          }

    In the parent (aspx):
    Create a global reference to the User Control
          protected YourUserControl YourUserControl1;

    Then to get the property:
          string newValue = YourUserControl1.ValueToPass;
    or to set the property:
          YourUserControl1.ValueToPass = "some value";

    NC...

     

    Friday, January 20, 2006 1:04 PM
  • User-2041805088 posted

    Yup that is the way to do it. However, the thing that I'm not clear about is why you would want to set the title for the aspx page in the ascx control when you can set it in the aspx page?

    If you want to change the title programatically in the code-behind of the aspx page, you can use this.Title.

    Friday, January 20, 2006 2:02 PM
  • User798903548 posted

    I dunno! Maybe he's got a TextBox or something in the UC that lets his users change the page title? Just guessing though.

     

    NC...

     

    Friday, January 20, 2006 2:16 PM
  • User-412120464 posted

    thanks for all answers

    Unfortunately there's no Property named this.Title in the code Behind of (aspx) page :(

     

    after I get the value from Property of (ascx) page How can I set it in Page Title :( ??

     

    and thanks with my regarding

    Fraas

    Friday, January 20, 2006 4:16 PM
  • User-2041805088 posted

    Sorry about that. Something from 2.0.

    Try the following (it's off the top of my head, so hopefully it should work):

    ASPX

    < title runat="server" id="pageTitle" > < / title >

    ASPX Code-behind

    protected System.Web.UI.HtmlControl.HtmlGenericControl pageTitle;

    public string PageTitle
    {
       get { return pageTitle.InnerText; }
       set { pageTitle.InnerText = value; }
    }

    ASCX Code-behind

    ASPXClassName.PageTitle = "someValue";

    Friday, January 20, 2006 4:34 PM
  • User-412120464 posted

    thanks for your reply
    it's work fine now :)

    with my regarding

    Friday, January 20, 2006 9:40 PM
  • User798903548 posted

    I believe that's in 2.0 and not in 1.0 or 1.1 so, in the aspx file, make your <title> tag look like this:
    <title><asp:literal id="controlTitleLiteral" runat="server" text="Default Title Goes Here"></asp:literal></title>

    That should add this to your CodeBehind file (if it doesn't, add it):
         protected System.Web.UI.WebControls.Literal controlTitleLiteral;

    Then to change the title:
         this.controlTitleLiteral.Text = "Some New Title";

    NC...

    Saturday, January 21, 2006 11:52 AM
  • User352867335 posted

    In ASP.Net 2.0:  ((System.Web.UI.Page)this.Parent.Page).Title = "My Title";

    Wednesday, April 14, 2010 3:37 PM
  • User1710254839 posted

    Maybe user is loading loading different ascx files due to conditions

    Saturday, October 9, 2010 11:30 AM
  • User-1274235969 posted

    this.Page.Title = "whatever title you want to give";

    Monday, June 18, 2018 6:11 AM