C
Cameron Eckman
For some reason I cannot get RegisterClientScriptBlock to render a script
reference on the page from a server control. Yes, I have not placed the code
in the Render method, I also tried the OnInit just in case. Below is the a
simple version of the code, any help is appreciated:
namespace MyCompany.Web
{
public class Header : System.Web.UI.WebControls.WebControl
{
private void RenderClientJavaScript(string javaScriptFilename)
{
string script = string.Format(@"<SCRIPT language=""javascript""
src=""/baxScripts/{0}.js""></SCRIPT>", javaScriptFilename);
if (! Page.IsClientScriptBlockRegistered(javaScriptFilename))
Page.RegisterClientScriptBlock(javaScriptFilename, script);
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
RenderClientJavaScript("basicToolset");
RenderClientJavaScript("webMenu");
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write("Hello World");
}
}
}
reference on the page from a server control. Yes, I have not placed the code
in the Render method, I also tried the OnInit just in case. Below is the a
simple version of the code, any help is appreciated:
namespace MyCompany.Web
{
public class Header : System.Web.UI.WebControls.WebControl
{
private void RenderClientJavaScript(string javaScriptFilename)
{
string script = string.Format(@"<SCRIPT language=""javascript""
src=""/baxScripts/{0}.js""></SCRIPT>", javaScriptFilename);
if (! Page.IsClientScriptBlockRegistered(javaScriptFilename))
Page.RegisterClientScriptBlock(javaScriptFilename, script);
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
RenderClientJavaScript("basicToolset");
RenderClientJavaScript("webMenu");
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write("Hello World");
}
}
}