简体   繁体   中英

Redirect on another page when I press a button

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...

url

Just do:

Response.Redirect("~/Default.aspx");

Note that this will redirect to Default.aspx in the root folder of your website.

一个远景,但仍然...如何使用Button2的PostBackUrl属性并创建一个跨页回发

在你的.aspx页面中,“Button2_Click”的make属性是ValidationGroup =“None”并检查!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM