Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

When I tried to execute this, without loading the alert message, straight away it navigates to homeNew.aspx page. But when the redirection code is not available, the alert message is popping up correctly... I need both function that means after clicking "ok" to the alert message It should be redirected to next page.. Please help me to overcome from this problem.

if (TextBox2.Text == nic)
{
    Response.Write(@"<script language='javascript'>alert('Check your email to retrieve your user name and password!')</script>");
    Response.Redirect("homeNew.aspx");
    connection.Close();
}
else
{
    Response.Write(@"<script language='javascript'>alert('INVALID Email address and NIC combination, Try Again!')</script>");
}
share|improve this question
change TextBox2.Text == nic to TextBox2.Text == "nic" – Satya 21 hours ago
nic may be a parameter and not a string literal. – RubbleFord 21 hours ago
nopes nic is a variable no problem in it, As I told response.write statement & response.redirect status are not working when both are there only response.redirect is working. If I dnt have that statement in that case response.write statement is working – Jiya 21 hours ago

2 Answers

up vote 2 down vote accepted

"Because the redirection, the java script you coded isn't run by the browser. You may code the redirection code inside your javascript.

if (TextBox2.Text == nic)
{
    Response.Write(@"<script language='javascript'>alert('Check your email to retrive your user name and password!'); window.location=""/homeNew.aspx""</script>");
}
else
{
    Response.Write(@"<script language='javascript'>alert('INVALID Email address and NIC combination, Try Again!')</script>");
}
share|improve this answer
Thanx a lot SuperLucky... :) – Jiya 21 hours ago
alert('Check your email to retrive your user name and password!');
window.location = '/homeNew.aspx';

You need to do both inside the script tag.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.