I want to do something like this:
I have a js file test4.js. The content is:
emp);
I inject test4.js in DNN module. However, I want to set the value of temp before including test4.js.
Here is my solution:
protected void Page_Init(System.Object sender, System.EventArgs e)
{
try
{
HtmlGenericControl oLink = new HtmlGenericControl("script");
oLink.Attributes["language"] = "javascript";
oLink.Attributes["type"] = "text/javascript";
oLink.Attributes["src"] = ModulePath + "test5.js";
Control oCSS = Page.FindControl("CSS");
if (oCSS != null)
{
oCSS.Controls.Add(oLink);
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected void Page_Load(System.Object sender, System.EventArgs e)
{
try
{
if (!ClientAPI.IsClientScriptBlockRegistered(this.Page, "test4.js"))
{
ClientAPI.RegisterClientScriptBlock(this.Page, "test4.js", "<script src='" + ResolveUrl("test4.js") + "'></script>");
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
The content of test5.js is:
var temp="This is a test";
It worked nice. However, I wonder if there is any bettern way to do it.
I don't want to set the value of temp in a different javascript file. I hope that I can assign it in server code.