kcwallace Posted June 27, 2005 Posted June 27, 2005 THis is probably a really dumb question, but is there another way other than the code below to dynamically change a page title at run time? Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) writer.RenderBeginTag(HtmlTextWriterTag.Title) writer.Write("ASFD") writer.RenderEndTag() writer.WriteLine() End Sub When I use the code above it overrides all the labels and text boxes on the form. Quote Go Beavs!!!
bri189a Posted June 28, 2005 Posted June 28, 2005 Page.RenderChildren(writer) I think is what you are looking for where you currently have writer.Write("ASDF")...didn't even know that enumeration exisited...don't do much of that sort of thing....someday I'll know it all :)....like I said earlier, we all need that kick...thanks! Quote
kcwallace Posted June 28, 2005 Author Posted June 28, 2005 I tried your suggestion, and it generates the following error: ... is not accessable in this context because it is 'protected' I placed it in the "Page_Load" function. Based on the error that is not the correct spot. Where should it be. Quote Go Beavs!!!
Joe Mamma Posted June 29, 2005 Posted June 29, 2005 in Onload do this - me.RegisterClientSideScript(string.format( "<SCRIPT language=""javascript"">document.title = ""{0}""; </SCRIPT>", sDocTitle) Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
david7777 Posted June 30, 2005 Posted June 30, 2005 in Onload do this - me.RegisterClientSideScript(string.format( "<SCRIPT language=""javascript"">document.title = ""{0}""; </SCRIPT>", sDocTitle) Only problem with this is if the user has disabled JavaScript... But then again, most websites nowdays use a lot of JavaScript and assume it will be available... Quote Bypass your proxy and get anonymous internet surfing FREE!
kahlua001 Posted June 30, 2005 Posted June 30, 2005 Dont believe search engines will pick up the javascript changed title. Quote
kcwallace Posted June 30, 2005 Author Posted June 30, 2005 in Onload do this - me.RegisterClientSideScript(string.format( "<SCRIPT language=""javascript"">document.title = ""{0}""; </SCRIPT>", sDocTitle) Is there anything I need to import to make that line work. I get the following error: 'RegisterClientSideScript' is not a member of 'myProjectName' Quote Go Beavs!!!
bri189a Posted July 1, 2005 Posted July 1, 2005 Page.RegisterStartUpScript to have script run as soon as page is loaded. Quote
david7777 Posted July 1, 2005 Posted July 1, 2005 I really would suggest that you avoid using JavaScript to accomplish this. I personally use MasterPage templates for my site which makes it very easy to dynamically change the title. If you dont want to do this, rather have a server side variable called PageTitle or something, and set it in your PageLoad. Then in your .aspx file, you can have <head><title><%=PageTitle%></title></head> I havent tried this, but it should work... Quote Bypass your proxy and get anonymous internet surfing FREE!
kcwallace Posted July 1, 2005 Author Posted July 1, 2005 MyBase.Response.Output.Write("<title>sss</title>") works perfectly Quote Go Beavs!!!
hrabia Posted July 5, 2005 Posted July 5, 2005 The right way to do this is to make your title tag "visible" to your code using HtmlGenericControl: html: <title runat="server" id=pageTitle>My Page</title> code: protected System.Web.UI.HtmlControls.HtmlGenericControl pageTitle; protected override void OnLoad(EventArgs e) { base.OnLoad (e); pageTitle.InnerHtml = "My Title from Code"; } Greets Adam Quote A man and a dog have an average of three legs. Beaware of Statistics.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.