HTML Page
<body>
<form id="form1" action="Default.aspx" method="post">
<input runat="server" id="txtuser" type="text" />
<input runat="server" id="txtpwd" type="password" />
<input type="submit" value="Login"/>
</form>
</body>
Code-behind
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Login();
}
}
private void Login()
{
if (checkUser(Request.Params["txtuser"],Request.Params["txtpwd"]))
{
Response.Redirect("Success.aspx");//if success
}
}
I am developing a web page for old mobile version (like nokia N70) facing a problem. When I submit my username and password then check user return true to redirect to a new page. But it won't redirect to success.aspx
. So I debug point on the Response.Redirect
code, it can stop there and I continue run become error because getting the username&password null. Then I realized it loaded the page twice. How to solve it?
You want to login when there IS a PostBack. Not the other way around.
Change
to
Make sure you have set
AutoEventWireup
to true in Code Front:otherwise Page_Load is never fired.