is it possible to change the keywords and title of a webform in code?
Many thanks
Nick
Printable View
is it possible to change the keywords and title of a webform in code?
Many thanks
Nick
Sure, do something like:
Declare the strMyTitle string variable as public, then set it in code. When the page is rendered, the contents of the variable will be written inside the title tag.Code:<title><%# strMyTitle %></title>
Do the same concept with anything else on the page.
Thanks!
well i've tried it and it doesn't work but i expect i've done something stupid.
I've declared strTitle as public at the top of the forms code, and in the form_load event set it. Then set it in the <title> tag in the html but it doesn't work.
Am i setting it in the wrong event?
Thanks
nick
Took me a while but I've found a LiteralControl method which you can use for this:
Code:Dim strWinTitleText as string = "New Window Title"
Me.Controls.Add(New LiteralControl("<title>" & _
strWinTitleText & "</title>"))
In the code hellswraith posted, change the pound sign to an equals so it looks like this:
here's a working example:Code:<title><%= strMyTitle %></title>
or you could do something like this:PHP Code:<script language="C#" runat="server">
private string _pageTitle = "";
public string PageTitle
{
get
{
return _pageTitle;
}
}
protected override void OnLoad(System.EventArgs e)
{
_pageTitle = "My Page Title";
}
</script>
<html>
<head>
<title><%= PageTitle %></title>
</head>
</html>
or if you wanna use code behind:PHP Code:<script language="C#" runat="server">
protected override void OnLoad(System.EventArgs e)
{
PageTitle.InnerText = "My Page Title";
}
</script>
<html>
<head>
<title id="PageTitle" runat="server"/>
</head>
</html>
here's the html side of things:and here's the code behind:Code:<html>
<head>
<title id="PageTitle" runat="server"/>
</head>
</html>
PHP Code:public class Default : System.Web.UI.Page
{
protected HtmlGenericControl PageTitle;
protected override void OnInit(EventArgs e)
{
PageTitle.InnerText = "My Page Title";
}
}