Hello people,
I'm new in this group, but I already have a few years on development in
C#.Net and VB.Net
I need to create the a javascript in the <head> tag.
So I tryed some ways that didn't worked.
1. I created an aspx that return the javascript code with
Response.Output.Write and put it in the src attribute.
<script type="text/javascript" src="GetJSChart.aspx?IdAcao=<%=
Request.QueryString["IdAcao"] %>"></script>
But the page GetJSChart.aspx was never called.
2. I tryed changing the page GetJSChart.aspx to HTTPHandler.
<script type="text/javascript" src="GetJSHandler.ashx?IdAcao=<%=
Request.QueryString["IdAcao"] %>"></script>
The handler was never called too.
3. Then a generated the code in the Page_Load and inserted in the <head>
HtmlGenericControl
script = new HtmlGenericControl("script");
script.Attributes.Add("type", "text/javascript");
script.InnerText = jsCode;
this.Header.Controls.Add(script);
But every " (quote) in the code was replaced to " and the js didn't
work.
I tryed to use HttpUtility methods to fix it, but the code still been
generated with "
4. So I use the generated code in the Page_Load and tryed to insert by
another way.
Page.ClientScript.RegisterClientScriptBlock(this.Header.GetType(), "sct",
jsCode, true);
This fixed the HTML Encoding.
But the code was inserted in the <body> tag. And I need in the <head>.
I know that this e-mail is a little confuse.
But if someone could help me to fix any of the solutions that I tryed to
create or have a better one, I'll apreciate it.
Thanks,
Alberto