1

Why doesn't my page redirect? The "Valid user" prompt pops up. But my page just does not redirect. What can be the issue?

protected void LoginButton_Click1(object sender, EventArgs e)
{
if (Page.IsValid)
{
User userLogin = new User();
userLogin.userId = this.txtUserName.Text.Trim();
userLogin.userPwd = this.txtPwd.Text.Trim();

string result = CommonFunctions.Check_ValidUser(userLogin);

if (result == "s")
{
Response.Write("<script>alert('" + "Valid user"+ "') ; location.href='Login.aspx'</script>");
Response.Redirect("DrugEntry.aspx",true);
}
else
{
string message = "We don't seem to have this user registered. Please try again.";
Response.Write("<script>alert('" + message + "') ; 
location.href='Login.aspx'</script>");
}
}
}
8
  • Did you try to debug by putting a breakpoint at that line? Commented Mar 25, 2014 at 9:36
  • does your page exists at the correct location? Commented Mar 25, 2014 at 9:44
  • 1
    Is your "DrugEntry.aspx" page is in same directory OR is in folder? Commented Mar 25, 2014 at 9:45
  • @shree.pat18 I did. It executes that line. But does not redirect. Commented Mar 25, 2014 at 9:46
  • 1
    Does your alert work if the user is not registered? You are constructing a string with an inverted comma in it and then passing the string to a javascript alert. Commented Mar 25, 2014 at 10:12

1 Answer 1

1

It seems that your code is correct.

Make sure that your page is in the same directory. If it is not in the same directory that use it as mentioned in below sample :

Response.Redirect("[Directory Name]/DrugEntry.aspx",true);
Sign up to request clarification or add additional context in comments.

2 Comments

Presumably trying to indicate where the directory name should go.
@Bharadwaj [Directory Name] means [folder name] in which page is located

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.