Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Go Beavs!!!
Posted
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!
Posted

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.

Go Beavs!!!
Posted

in Onload do this -

 

me.RegisterClientSideScript(string.format( "<SCRIPT language=""javascript"">document.title = ""{0}""; </SCRIPT>", sDocTitle)

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.

Posted
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...

Bypass your proxy and get anonymous internet surfing FREE!
Posted
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'
Go Beavs!!!
Posted

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...

Bypass your proxy and get anonymous internet surfing FREE!
Posted

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

A man and a dog have an average of three legs.

Beaware of Statistics.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...