Hi Maxim,
Thanks for posting in the community!
From your description, you embed an UserControl into a webpage, the
UserControl has a Public string property so that you can use the value of
this property to set the UserControl's container page's title via such code:
<title>
<%=TitleUC1.PageTitle %>
</title>
However, you found that the page's title value will disappear after the
page is posted back.
Also, you're looking for anyother approachs to set the page's title, yes?
If there is anything I misunderstood, please feel free to let me know.
Based on my research, as for your first problem, I agree to Tu-Thach and
coder5811's suggestion that you need to set the UserControl's PageTitle
Property not only when the page is first time loaded but also when posted
back. For example, use the below code in UserControl:
if(!IsPostBack)
{
PageTitle = "Initial Title";
}
else
{
//the case when page is posted back
PageTitle = txtPageTitle.Text;
}
Thus, the title won't disappear when the page is posted back.
As for any other approachs to set the page's title, I found there is
another means to set the page's title dynamically------------set the
<titile>element as runat=server and provide an unique id, For example,
specify the titile in page as below:
.........
<HEAD> <TITLE ID="MyTitle" RUNAT="server"> </TITLE> </HEAD>
...........
and also need to declare a HtmlGeneralControl member in the codebehind
page class like:
public class TestTitle : System.Web.UI.Page
{
.......
protected System.Web.UI.HtmlControls.HtmlGenericControl MyTitle;
.............
Then, we can specify the page's title dynamically by change the MyTitle
member's InnerText property, just as:
private void Page_Load(object sender, System.EventArgs e)
{
MyTitle.InnerText = "My Custom Title!";
}
In addtion, here is weblinks to some tech artiles which have dicussed on
this topic, you may have a view if you feel any thing unclear:
#How to Change the Page Title in ASP.NET dynamically
http://www.dotnetspider.com/Technology/Samples/ShowSample.aspx?SampleId=12
#Setting the ASP.NET Page Title and Meta Tags
http://authors.aspalliance.com/chrisg/default.asp?article=141
Please try out the preceding suggestions. If you have any questions, please
feel free to let me know.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)