postback problem

  • Thread starter Thread starter Regus
  • Start date Start date
R

Regus

I have a form with 2 buttons
* submit
* cancel

When the submit-button is clicked, the form must be submitted. When the
cancel-button is clicked, the page must redirect to the start page.
The problem is this : the cancel-button makes a postback , so my code
doesn't work good. My code is :

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
if page.ispostback then
'submit form
endif
end sub

The cancel-button event
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Response.Redirect("../start.aspx")
End Sub

In this way, the form is submitted when the submit-button is clicked, but
also when the cancel-button is clicked.
Is there a way to solve this ?
 
You could use a simple HTML button like this:


<BUTTON id="mybutton" onclick="document.location.href='startpage.aspx';" name="mybutton" type="button" value="Button">Cancel</BUTTON>
 
Regus said:
I have a form with 2 buttons
* submit
* cancel

When the submit-button is clicked, the form must be submitted. When
the cancel-button is clicked, the page must redirect to the start
page.
The problem is this : the cancel-button makes a postback

What about moving the "submit-code" to a submit-button event, and not use
page_load() for this matter?
 
Back
Top