Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing parent page's title from user control

Tags:

c#

asp.net

I am a newbie to asp.net. I have an asp.net page which uses a user control. On Page_Load event of this control, I want to change the title of the parent aspx page. I need help on this please.

like image 525
user74042 Avatar asked Jun 24 '09 22:06

user74042


3 Answers

protected void Page_Load(object sender, EventArgs e)
{
    Page.Title = "New Title";
}
like image 91
Chris Mullins Avatar answered Sep 23 '22 19:09

Chris Mullins


You can try create a property in usercontrol and next call this property using your instance of usercontrol in page like

In UserControl

    protected void Page_Load(object sender, EventArgs e)
    {
        this.MyProperty = "This is a test";
    }

    public string MyProperty { get; set; }

` In Page

    protected void Page_Load(object sender, EventArgs e)
    {
        WebUserControl11.PreRender += new EventHandler(WebUserControl11_PreRender);
    }

    void WebUserControl11_PreRender(object sender, EventArgs e)
    {
        string str = WebUserControl11.MyProperty;
        this.Header.Title = str;
    } 
like image 30
pedrofernandes Avatar answered Sep 20 '22 19:09

pedrofernandes


Set this in your USERCONTROL:

this.Page.Master.Page.Header.Title = "text text title title";
like image 42
Fabio Avatar answered Sep 20 '22 19:09

Fabio