postback problem

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 ?
 
S

Steve C. Orr, MCSD

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

Marius Hildebrandt

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top