A
Amir Tohidi
Hi
I am trying to inject a piece of JavaScript into my pages (using the
MasterPage).
I need to send the session time out value to the client (the code is below).
Whilst I can step into the Page_Unload() method and see the script get
registered, I can not see the script in the pages source file once it has
appeared in the browser.
Anyone see what I am doing wrong?
Thanks
public partial class MasterPage : System.Web.UI.MasterPage
{
string TIMEOUT_SCRIPT =
@"<script language=""JavaScript"">
<!--
setTimeout(""timedOut()"", ###);
function timedOut()
{
document.getElementById('TimeoutLabel1').style.visibility = 'visible';
}
// -->
</script>";
protected void Page_Load(object sender, EventArgs e)
{
// Update the version label
LabelVersionInfo.Text = "JHAdmin version:" +
Assembly.GetExecutingAssembly().GetName().Version;
}
protected void Page_Unload(object sender, EventArgs e)
{
//this.SessionTimeoutControl1.Foo();
// Calculate the number of seconds to time out
int timeOutInSeconds = Page.Session.Timeout * 60 * 1000;
string numberOfSeconds = timeOutInSeconds.ToString();
// Put the script on the page that will make the label visible once
the session has timed out
Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptKey",
TIMEOUT_SCRIPT.Replace("###", numberOfSeconds));
}
}
I am trying to inject a piece of JavaScript into my pages (using the
MasterPage).
I need to send the session time out value to the client (the code is below).
Whilst I can step into the Page_Unload() method and see the script get
registered, I can not see the script in the pages source file once it has
appeared in the browser.
Anyone see what I am doing wrong?
Thanks
public partial class MasterPage : System.Web.UI.MasterPage
{
string TIMEOUT_SCRIPT =
@"<script language=""JavaScript"">
<!--
setTimeout(""timedOut()"", ###);
function timedOut()
{
document.getElementById('TimeoutLabel1').style.visibility = 'visible';
}
// -->
</script>";
protected void Page_Load(object sender, EventArgs e)
{
// Update the version label
LabelVersionInfo.Text = "JHAdmin version:" +
Assembly.GetExecutingAssembly().GetName().Version;
}
protected void Page_Unload(object sender, EventArgs e)
{
//this.SessionTimeoutControl1.Foo();
// Calculate the number of seconds to time out
int timeOutInSeconds = Page.Session.Timeout * 60 * 1000;
string numberOfSeconds = timeOutInSeconds.ToString();
// Put the script on the page that will make the label visible once
the session has timed out
Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptKey",
TIMEOUT_SCRIPT.Replace("###", numberOfSeconds));
}
}