Setting page title in .Net using C # from class

Question

How to set page title from class. Is it possible? I can and set the page title from the page itself and user control.

Can I do this through a class using C # .Net

Here is what I want to do. On an Aspx page, I want to call a function that runs in the line header and assign the page title to the class.

SomePage.Aspx.CS

page_onload() { setPageTitle(titleValue); } 

SetPageTitleClass.CS

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

Problem: "Page.Title" is not available in class

+4
source share
4 answers

First: why do you have to do this? --- return it and let the page install it ... u can install it in the base class or the main page.

If you still want to do this, follow these lines:

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

You will need to pass a link to the page where you want to set the title of the C # class that you are going to use.

Could you tell us more about what you are trying to do?

0
source

I think the best way would be for the class to throw a TitleChanged event that the page can subscribe to.

Thus, you will not be closely related to your decision, and everything will be fine and clean.

0
source

Yes. You must hold the Page object. In Page and UserControls, this is relatively simple.

 Page.Title = "My Title"; 
-2
source

All Articles