Reputation: 115
I control if a user exist in database. If it dont exist, I want to stay login page. If it exist, I want to go Default.aspx page.
protected void BtnLogin_Click(object sender, EventArgs e)
{
if(condition is okey)
{
// go default.aspx
}
else
{
//stay this page
}
}
What can I write on comment lines to achive this? Thanks!
Upvotes: 1
Views: 137
Reputation: 25221
Sounds like you just want to do a redirect:
protected void BtnLogin_Click(object sender, EventArgs e)
{
if(myCondition)
{
Response.Redirect("/default.aspx");
}
else
{
//stay this page
}
}
If you want to retain the POST data, you can use Server.Transfer
instead (note: based on your edits, it doesn't sound like this is what you need - I think you just need Response.Redirect
):
Server.Transfer("/default.aspx");
Note that transferring the handler of the POST like this will not cause a browser redirect and therefore will not change the browser URL.
If you need to actually POST to a different URL and have the browser update, you'll need to post directly to that URL using a cross-page postback (using the action
attribute on the form element), validate on that page and then redirect back to the original page if validation fails.
Upvotes: 2