views:

42

answers:

1

Hi, I need help in how to set webform control proprieties in asp.net and ajax control using javascript.

I have asp page that has checkBox, TextBox, MaskedEditExtender, and RegularExpressionValidator.

I set the mask for MaskedEditExtender as Mask="(999)999-9999" and I set the ValidationExpression for RegularExpressionValidator as ValidationExpression="\d{10}".

I want to change these two properties when user checked the international checkbox to: Mask="999999999999" and as ValidationExpression="\d{12}" Using JavaScript without interrupting with server side and when the user unchecked they get previous value so the interaction should be only in the client side.

Please help me with this and here is my code:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">

      function pageLoad() {
      }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:CheckBox ID="chkIntphoneHome" runat="server"  Text="Internation Code" 
                AutoPostBack="false"/>

            <asp:TextBox ID="txtHomePhone" runat="server"></asp:TextBox>


        <cc1:MaskedEditExtender ID="txtHomePhone_MaskedEditExtender" runat="server" 
            AutoComplete="False" CultureAMPMPlaceholder="" 
            CultureCurrencySymbolPlaceholder="" CultureDateFormat="" 
            CultureDatePlaceholder="" CultureDecimalPlaceholder="" 
            CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True" 
            Mask="(999)999-9999" TargetControlID="txtHomePhone">
        </cc1:MaskedEditExtender>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
            ErrorMessage="RegularExpressionValidator" ControlToValidate="txtHomePhone" 
            ValidationExpression="\d{10}"></asp:RegularExpressionValidator>        

    </div>
    </form>
</body>
</html>
A: 

Instead of meddling with the maskEditor/validator controls' client-side behaviour, are you OK with having 2 sets of textbox+maskExtender+validator?

Set 1 = texbox_HomePhone + maskEditExtender_HomePhone + regexValidator_HomePhone
Set 2 = texbox_IntHomePhone + maskEditExtender_IntHomePhone + regexValidator_IntHomePhone

Using the checkbox to toggle (via javascript) the display/hidding of either set.

o.k.w
Thank you for this idea but I want to learn how to change controls' client-side behavior using JavaScript.I would appreciate it if you can help me with thatRegards
Eyla
Though it might be possibe, it could get messy as you'll need to 'hack' into the client-side validation methods (the server-side ones probably easier). You might want to take a look at the validation client-side API at http://msdn.microsoft.com/en-us/library/aa479045.aspx
o.k.w