Below are my coding (C#) for the Login webpage (using Visual Studio) to activate a countdown timer at the Master page when I clicked on the "Login" button at the Login Page. The system are able to redirect to the StaffWelcome Page but the Timer() function (javascript.js) at the master.site was not executed. But if I removed the Respond.Redirect statement the Timer() function at the master.site was executed successfully. Thus, I need the expertise advice on how to make the Timer() continue to countdown on every webpage while redirect to the Welcome Page upon authentication successfully.
protected void LoginBtn_Click(object sender, EventArgs e)
{
if (AuthenticateUser(txtUserName.Text, txtPassword.Text))
{
Master.Timer();
Session["username"] = txtUserName.Text;
Response.Redirect("~/StaffWelcomePage.aspx?UserName=" + txtUserName.Text);
}
else
{
MsgBox("Invalid User Name and/or Password");
lblMessage.Text = "Invalid User Name and/or Password";
}
}
The coding method at the site.master are shown below.
public void Timer()
{
Page.ClientScript.RegisterStartupScript(GetType(), "Javascript", "countdownJS()", true);
}
The Countdown script file at the script folder are as shown below:
function countdownJS()
{
startTimer();
function startTimer() {
var presentTime, timeArray, m, s, x;
presentTime = document.getElementById('lblTimer').innerHTML;
timeArray = presentTime.split(/[:]+/);
m = timeArray[0];
s = checkSecond((timeArray[1] - 1));
x = m.toString() + s.toString();
if (s == 59) { m = m - 1 }
if (x == 500) { window.open("http://asc-insilico/ASCDomainFB/Reminder5Min.aspx", "CountdownTimer", "height=200,width=500"); }
if (x < 1) { window.location = "http://asc-insilico/ASCDomainFB/LoginPage.aspx"; }
document.getElementById('lblTimer').innerHTML = m + ":" + s;
setTimeout(startTimer, 1000);
}
function checkSecond(sec) {
if (sec < 10 && sec >= 0) { sec = "0" + sec };
if (sec < 0) { sec = "59" };
return sec;
}
}
What I have tried:
CodeProject, W3Schools, Google Search, Stackoverflow.