C
Casper Hornstrup
In my webcontrol, I register some javascript once. If I do it like below,
the script is output.
private const string HintJavascriptResourceName = "CsiteWeb.Hint.js";
private const string HintStartupScriptName = "Csite.Web.Hint.js";
private void RegisterScript()
{
if (Page.IsStartupScriptRegistered(HintStartupScriptName))
{
return;
}
using (Stream rs = System.Reflection.Assembly.GetCallingAssembly().
GetManifestResourceStream(HintJavascriptResourceName))
{
byte[] rsbuf = new byte[rs.Length];
rs.Read(rsbuf, 0, (int)rs.Length);
string script = System.Text.Encoding.UTF8.GetString(rsbuf, 0,
(int)rs.Length);
Page.RegisterStartupScript(HintStartupScriptName,
String.Format("<script>{0}\ncsiteHintRegister();</script>", script));
}
}
Now, I have a problem that the script is output a the bottom of the page, so
sometimes explorer complains that a function is used before it is declared.
Using IsClientScriptBlockRegistered and RegisterClientScriptBlock instead
should put the script at the top of the page right? However, the script is
not output to the page when using IsClientScriptBlockRegistered and
RegisterClientScriptBlock. How can this be?
Casper
the script is output.
private const string HintJavascriptResourceName = "CsiteWeb.Hint.js";
private const string HintStartupScriptName = "Csite.Web.Hint.js";
private void RegisterScript()
{
if (Page.IsStartupScriptRegistered(HintStartupScriptName))
{
return;
}
using (Stream rs = System.Reflection.Assembly.GetCallingAssembly().
GetManifestResourceStream(HintJavascriptResourceName))
{
byte[] rsbuf = new byte[rs.Length];
rs.Read(rsbuf, 0, (int)rs.Length);
string script = System.Text.Encoding.UTF8.GetString(rsbuf, 0,
(int)rs.Length);
Page.RegisterStartupScript(HintStartupScriptName,
String.Format("<script>{0}\ncsiteHintRegister();</script>", script));
}
}
Now, I have a problem that the script is output a the bottom of the page, so
sometimes explorer complains that a function is used before it is declared.
Using IsClientScriptBlockRegistered and RegisterClientScriptBlock instead
should put the script at the top of the page right? However, the script is
not output to the page when using IsClientScriptBlockRegistered and
RegisterClientScriptBlock. How can this be?
Casper