Re: Which button was clicked to cause validation?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Which button was clicked to cause validation?

From: <ujjc001@gmail.com>
Date: Wed Nov 30 2005 - 16:37:37 CET

asp button. has server side code. has a custom validator.
The server side code does not execute until the validation has ran.
in the client side javascript code for the custom validator, can I call
any type of a function to see what event caused the page to attempt
submit hence calling all validation.
Yes it's in a form.
The two buttons are btnSearchAddress and btnSearchParcel.
For instance, when <asp:customvalidator id="val_cust_ByAddress"
runat="server" Display="None"
ClientValidationFunction="val_cust_ByAddress_ClientValidate"></asp:customvalidator>
runs it calls
function val_cust_ByAddress_ClientValidate(sender, args)
{
if (document.getElementById("txtNumber").value == "")
        {
                document.getElementById("val_cust_ByAddress").errormessage = "You
must enter a house number";
                args.IsValid = false;
                return;
        }
}

and in there I want to test if search by address was clicked or by
parcel.

 Here's some more of the code.

<form id="Form1" method="post" runat="server">
                        <TABLE id="Table1" cellSpacing="0" cellPadding="0" width="536"
border="0">
                                <TR>
                                        <TD class="text_basic_10" vAlign="top">
                                                        <TABLE id="Table4" cellSpacing="0" cellPadding="0" width="536"
border="0">
                                                        <TR>
                                                                <TD class="text_basic_8" style="WIDTH: 352px">
                                                                        <asp:button id="btnClearAddress" runat="server" Width="48px"
CssClass="button" Text="Clear"
                                                                                CausesValidation="False"></asp:button></TD>
                                                                <TD class="text_basic_8" style="WIDTH: 85px"></TD>
                                                                <TD class="text_basic_8" align="right">
                                                                        <asp:button id="btnSearchAddress" runat="server" Width="48px"
CssClass="button" Text="Search"></asp:button></TD>
                                                        </TR>
                                                </TABLE>
                                                <TABLE id="Table5" cellSpacing="0" cellPadding="0" width="536"
border="0">
                                                        <TR>
                                                                <TD class="text_basic_8" style="WIDTH: 106px"><asp:button
id="btnClearParcel" runat="server" Width="48px" CssClass="button"
Text="Clear" CausesValidation="False"></asp:button></TD>
                                                                <TD class="text_basic_8" style="WIDTH: 115px"></TD>
                                                                <TD class="text_basic_8" style="WIDTH: 3px"></TD>
                                                                <TD class="text_basic_8" align="right"><asp:button
id="btnSearchParcel" runat="server" Width="48px" CssClass="button"
Text="Search"></asp:button></TD>
                                                        </TR>
                                                </TABLE>
                                        </TD>
                                </TR>
                        </TABLE>
                        <asp:customvalidator id="val_cust_ByAddress" runat="server"
Display="None"
ClientValidationFunction="val_cust_ByAddress_ClientValidate"></asp:customvalidator><BR>
                        <asp:customvalidator id="val_cust_Street" runat="server"
Display="None"
ClientValidationFunction="val_cust_Street_ClientValidate"></asp:customvalidator>
                        <BR>
                        <asp:customvalidator id="val_cust_City" runat="server"
Display="None"
ClientValidationFunction="val_cust_City_ClientValidate"></asp:customvalidator>
                        <BR>
                        <asp:customvalidator id="val_cust_ZipCode" runat="server"
Display="None"
ClientValidationFunction="val_cust_ZipCode_ClientValidate"></asp:customvalidator><BR>
                        <BR>
                        <asp:customvalidator id="val_cust_ParcelIDNumber" runat="server"
ErrorMessage="Parcel ID number required"
                                Display="None"></asp:customvalidator><BR>
                        <BR>
                        <asp:validationsummary id="val_summary" runat="server" Width="216px"
HeaderText="The following errors were found:"
                                ShowSummary="False" ShowMessageBox="True"></asp:validationsummary>
                        <script language="javascript">
                                function val_cust_ByAddress_ClientValidate(sender, args)
                                        {
                                                if (document.getElementById("txtNumber").value == "")
                                                {
                                                        document.getElementById("val_cust_ByAddress").errormessage =
"You must enter a house number";
                                                        args.IsValid = false;
                                                        return;
                                                }
                                        }

                                function val_cust_Street_ClientValidate(sender, args)
                                        {
                                                if (document.getElementById("txtStreet").value == "")
                                                {
                                                        document.getElementById("val_cust_Street").errormessage = "You
must enter a street name";
                                                        args.IsValid = false;
                                                        return;
                                                }
                                        }

                                function val_cust_City_ClientValidate(sender, args)
                                        {
                                                if (document.getElementById("ddlMunicipality").value == "-1" ||
document.getElementById("ddlMunicipality").value == "0")
                                                {
                                                        document.getElementById("val_cust_City").errormessage = "You
must select a city";
                                                        args.IsValid = false;
                                                        return;
                                                }
                                        }

                                function val_cust_ZipCode_ClientValidate(sender, args)
                                        {
                                                if (document.getElementById("ddlZipCode").value == "-1" ||
document.getElementById("ddlZipCode").value == "0")
                                                {
                                                        document.getElementById("val_cust_ZipCode").errormessage = "You
must select a zip code";
                                                        args.IsValid = false;
                                                        return;
                                                }
                                        }

                        </script>
                </form>
Received on Sat Dec 3 04:33:35 2005