|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
<Head>Tagwrite 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- :-) Here's a guy who wrote a whole article on it :)
http://www.codeproject.com/aspnet/scriptregister.asp My simple solution would be to give the <head> tag a runat=server attribute so can manipulate its contents with asp. Your first solution is a good joke I hope you learned by now ;) Cheers, Tom Pester Show quoteHide quote > 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- :-) > 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) Show quoteHide quote "Sam Samnah" <webmaster***@terraquest123.ca> wrote in message news:OelWOjUbFHA.1044@TK2MSFTNGP10.phx.gbl... > 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- :-) > > 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? Show quoteHide quote "Bruce Barker" <brubar_nospamplease_@safeco.com> wrote in message news:e%23ToptUbFHA.3400@tk2msftngp13.phx.gbl... > 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) > > > "Sam Samnah" <webmaster***@terraquest123.ca> wrote in message > news:OelWOjUbFHA.1044@TK2MSFTNGP10.phx.gbl... >> 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- :-) >> >> > >
Other interesting topics
Asynchronous Call
PostBack problem HttpWebRequest.GetResponse on POST returns 405 method not allowed LDAP Query Help datagrid - do not refresh the contents in the grid How to solve this " problem adding html to body Cannot use integrated security from a thread in ASP.Net/ Windows 2 Creating a "serverless" app... loading session variables in page title bar |
|||||||||||||||||||||||