<Head>Tag

S

Sam Samnah

Ok I have a bit of a problem with a Server control I am building. I need to
write a client-side Javascript block between the open and closing Head tag.
I have tried the following methods:

first attempt
Page.Response.AppendHeader(someStringBuilder);
result:
Returned nothing on the page.

Second attempt
if(!Page.IsStartupScriptRegistered("startup")){

StringBuilder jsLoad=new StringBuilder();

jsLoad.Append(@"Some Javascript");

string CMSCScript=jsLoad.ToString();

Page.RegisterClientScriptBlock("startup",CMSCScript);

}

Result:

Returned Client Script at the top between the Open and Close <Body> tags.



I need to place the script block between the Open and Close <Head> tags.
Can someone tell me how this is done? By the way, for the above code I
override the PreRender() method.

Can someone please help me with this or lead me to the right web site for a
guide. Thank you.

I am Sam- :)
 
B

Bruce Barker

asp.net doesn't support this directly.

1) Page.Response.AppendHeader(), adds a response header , which comes before
any html.
2) Page.RegisterClientScriptBlock(), renders the script block (you must
include the script tags), right after the <form>
3) Page.RegisterStartupScript, renders the script block right before the
</form>

if you want to add code in the header, you need to add a runat on the
header. then using the HtmlGeneric control you can create script blocks. or
you can get the innerHtml from the header, and insert the script blcks
directly.


<header id="myHeader" runat=server>
</header>

-- bruce (sqlwork.com)
 
S

Sam Samnah

Thanx Bruce for replying.

I need to be able to place the client script directly from the custom server
control I'm building. How can I set the containing page head tag directly
from my server control to Runat="server" if I can't access the Head tag
element from my control to begin with?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top