Click here to Skip to main content
15,905,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project, in a page I ask the users to register certain details . It is later updated
in SQL database. I use 'SUBMIT' and 'CANCEL' buttons in this page. What happens is both the buttons are performing the same job. My 'CANCEL' button is not going to the default page.
Hereunder are my codes:


CSS
<asp:Button ID="Button4" runat="server"
 onclick="Button4_Click"
        style="z-index: 1; left: 185px; top: 2840px; position: absolute" Text="Submit" />
  <asp:Button ID="Button5" runat="server" PostBackUrl="Default.aspx"
        onclick="Button5_Click"
        style="z-index: 1; left: 300px; top: 2840px; position: absolute" Text="Cancel" />



C#
protected void Button5_Click(object sender, EventArgs e)  // cancel button
    {
        Response.Redirect("Default.aspx");
    }
Posted
Updated 22-Feb-13 16:35pm
v2
Comments
maxrockM 22-Feb-13 22:36pm    
Remove PostBackUrl and try
S.Rajendran from Coimbatore 22-Feb-13 23:14pm    
I tried but doesnt work.
_Amy 22-Feb-13 23:33pm    
Where is Button4_Click event's code? Can I see that?
Sergey Alexandrovich Kryukov 3-Apr-13 1:05am    
Please don't post non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

try this in aspx page:
ASP.NET
<asp:button id="Button4" runat="server" xmlns:asp="#unknown">
 onclick="Button4_Click"
        style="z-index: 1; left: 185px; top: 2840px; position: absolute" Text="Submit" />
  <asp:button id="Button5" runat="server">
        onclick="Button5_Click"
        style="z-index: 1; left: 300px; top: 2840px; position: absolute" Text="Cancel" /></asp:button></asp:button>


try this in codebehind:
C#
protected void Button5_Click(object sender, EventArgs e)  // cancel button
    {
        Response.Redirect("Default.aspx");
    }
protected void Button4_Click(object sender, EventArgs e)  // submit button
    {
        //code for registering user
    }
 
Share this answer
 
Comments
Avinash Shewale 22-Feb-13 22:42pm    
in button4_click()
after finishing your register logic, you can redirect to anotherpage to show message that registration is successful:

//code for registering user
....
....
Response.Redirect("anotherpage.aspx");
Solution 1:

C#
protected void Button5_Click(object sender, EventArgs e)  // cancel button
    {
        this.close() 
    }


Solution 2:


A. Write the Below code in Page_Load Event
Button5.Attributes.Add("onClick", "self.location.replace("default.aspx")")

B. And Remove, onclick="Button5_Click" FROM .aspx
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 22-Feb-13 23:38pm    
A. Many syntax error is coming
B. this.close() is not accepting, throws error.
MalwareTrojan 22-Feb-13 23:41pm    
this.Close();
MalwareTrojan 22-Feb-13 23:55pm    
Is it working now with this.Close();
If not then Try Soliution 2 of Solution 2

And let me know the results.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900