Search code examples
c#.netclassmethodspage-title

Setting the Page-Title in .Net using C# from a Class


Question,

How do i set the title of a page from a class. Is it even possible? I can and have set the page title from a page itself and a usercontrol.

Can I, How Do I do this via a class using C# .Net

Here is what im looking to do, From the Aspx Page i want to call a function that passes in the string title, and have the class set the page title.

SomePage.Aspx.CS

page_onload()   {   setPageTitle(titleValue);   }

SetPageTitleClass.CS

public static void setPageTitle(string iTitle)   {   Page.title = iTitle;  }

The problem is "Page.Title" is not available from the Class


Solution

  • First: why would you want to do that? --- give it back and let the page set it ... u can set it in a base class or master page.

    If you still want to do it, is along the lines:

    var page = (Page)HttpContext.Current.Handler;
    page.Title = "someTitle";