Cancel a Form using an HTML Submit Button

Results 1 to 2 of 2

Thread: Cancel a Form using an HTML Submit Button

  1. #1
    Join Date
    Dec 1969

    Default Cancel a Form using an HTML Submit Button

    Hi, <BR>I am working on an application that logs incoming calls. <BR><BR>I have previously done form validation using code-behind code that I write. However, I want to make my forms run faster by using validation controls instead. I added a Cancel button in case the user wants to cancel the record being created, but I still want to save the information on the user&#039;s reason for cancelling the call. My cancel button looks like this: <BR><BR>&#060;b&#062;&#060;input id=btnCancel onclick="Page_ValidationActive=false;" type="submit" value="cancel call" &#062;&#060;/b&#062; <BR><BR>Then I added the following script to the page load event: <BR>============================================== ========= <BR>&#060;b&#062; <BR>If Page.IsPostBack Then <BR> Page.Validate() <BR> If Not Page.IsValid Then <BR> Dim strMessage As String <BR> If (txtCancelReason.Text = Nothing) Then <BR> strMessage = "Enter the reason for cancellation." <BR><BR> &#039;finishes server processing, returns to client. <BR> Dim strScript As String = "&#060;script language=JavaScript&#062;" <BR> strScript += "alert(""" & strMessage & """);" <BR> strScript += "&#060;/script&#062;" <BR><BR> If (Not Page.IsStartupScriptRegistered("clientScript")) Then <BR> Page.RegisterStartupScript("clientScript", strScript) <BR><BR> End If <BR> Else &#039;a reason for cancelling the call has been entered, <BR> &#039;so it is ok to leave this form. <BR> Server.Transfer("index.aspx") <BR> Exit Sub <BR> End If <BR><BR> End If <BR>End If <BR>&#060;/b&#062; <BR>================================ <BR>It works perfectly when there are invalid fields, because it triggers the "If not page.isvalid" condition. However, if all the required fields have been completed, then it does not meet this condition, and the call is not cancelled. I have been trying to find a way to programmatically identify the button that caused the page to submit, because then I could make the code conditional on the cancel button being used, but it is an html button, not an asp control. Does anyone know how to do that, or have any better suggestions?

  2. #2
    Join Date
    Dec 1969

    Default RE: Cancel a Form using an HTML Submit Button

    use a web control instead<BR><BR>&#060;b&#062;&#060;input id="btnCancel" onClick="DoCancel" text="Cancel Call" runat="server" CauseValidation="False"/&#062;&#060;/b&#062;<BR><BR>in the code<BR><BR>Public Sub DoCancel(obj as Object, e as EventArgs)<BR> Response.Redirect("wherever")<BR>End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts