Client side dilemma

I'm trying to ensure that I can run a piece of client script when the user presses a button to submit a form, but I only want to run it *if* the Form has been validated and only if a specific button has been pressed.  In other words there could be fifty controls that would cause postbacks, I only want my client side script to run for a particular control... how do I do that again?

 

<%@ Page Language="vb" %>
<%@ Import namespace="System.Text.RegularExpressions" %>

<script language="vb" runat="server">
    Sub Page_Load()
        If Not IsPostBack Then
            enterButton.Attributes.Add("onclick", "SpeakBeforeSubmit() ;")
        End If
    End Sub

    Sub enterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Regex.IsMatch("dddddddddddddddddddd9", "^(d+ ?)+$") Then
            ' dunno? :-)
        End If
    End Sub
</script>


<HTML>
    <HEAD>
    <title>DoExpensiveStuff</title>
    <script language="javascript">
    <!--
        function SpeakBeforeSubmit() {
            alert("Submitting Now!") ;
        }
    -->
    </script>
    </HEAD>
    <body>
    <form id="Form1" runat="server">

<asp:Textbox 
    id="ntr" 
    runat="server" 
/> 
<asp:RequiredFieldValidator 
    id="reqntr" 
    controltovalidate="ntr" 
    ErrorMessage="enter a value" runat="server"
/>
<asp:Button 
    id="enterButton" 
    onclick="enterButton_Click" 
    runat="server" 
    Text="Do lotsa Stuff!" 
/>

    </form>
    </body>
</HTML>

2 Comments

  • The only thing that immediately comes to mind is CausesValidation. Although, it seems like that is the *opposite* of what you would like to do...the default is true, but perhaps you could set it to false at the Page level, then set the only one you want to be true.

  • Have you gotten this resolved yet, Darren? How about adding another validator to do the work for you? CustomValidator maybe?:)

Comments have been disabled for this content.