Link to home
Start Free TrialLog in
Avatar of WEhalt
WEhaltFlag for United States of America

asked on

Javascript - vb.net ; check for form validation before click event

I have a page that uses vb processes for a cancel and a save button click.  Is there a way to make these buttons check with one of the javascript functions before performing their actions?  

'On this one I would like to verify with the user whether or not they really wish to proceed if any of the values on the form were changed.
Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click

        BindGrid()

    End Sub

Open in new window


'On this one I would like to run the Business Rule validation before allowing the save
    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click

        SaveDailyClose()
        Response.Redirect("Disposal.aspx")

    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WEhalt

ASKER

I see the example, but I not 100% sure it will work the same because my click event is in my vb code file.  The example shows them as part of the page script.

In the following example, if I add the OnClientClick attribute to the button, will the function btnNext_Click. in VB, never run?


code in object Inbound.aspx
=======================================
    <script language="javascript" type="text/javascript">

        function stopTheButton() {
            return false;
        }
....
<body>
  <form id="form1" runat="server">
    <asp:Button ID="btnNext" Runat="server"
        OnClientClick="return stopTheButton();"
        Text="Save/Next" />
...

vb code in object Inbound.aspx.vb
=======================================
    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
        SaveDailyClose()
        Response.Redirect("EndProduct.aspx")
    End Sub