Reputation: 993
I'm working on a project and I have a problem. I have 2 pages. First page is Default.aspx Second page is Registration.aspx (with button Submit and Cancel)
What I want to do is to press a Button_Cancel on Registration.aspx to redirect me on page Default.aspx I tried all possibilities like
Response.Redirect(Page.ResolveClientUrl("~/Default.aspx"));
or Response.Redirect("Default.aspx");
but when I press button Cancel it do not redirect me on Default page.
Here is the code for buttons Submit and Cancel:
//Submit Button
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
lblResult.Text = ("Words were successfully introduced. !");
lblResult.ForeColor = System.Drawing.Color.Green;
Response.Write("Your registration is successful !");
}
else
{
lblResult.Text = "Incorrect words. Please try again.";
lblResult.ForeColor = System.Drawing.Color.Red;
}
}
//Cancel Button
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
On Registration page I have some fields with UserName, Email, Password etc. When I press Button_Cancel I receive Error Messages to complete that fields...
Upvotes: 0
Views: 1113
Reputation: 988
In your .aspx page make property of "Button2_Click" is ValidationGroup="None" and check !!
Upvotes: 0
Reputation: 1844
A long shot, but still... How about using a PostBackUrl attribute of a Button2 and create a cross page postback?
Upvotes: 0
Reputation: 59232
Just do:
Response.Redirect("~/Default.aspx");
Note that this will redirect to Default.aspx
in the root folder of your website.
Upvotes: 2