0
votes

I use RegularExpressionValidators for the input text-boxes in my ASP.NET forms.

The GUI appears like. All the items are server controls and upon leaving the text box, I would display error message if the input is invalid.

I have enabled client-side validation with EnableClientScript in the RegularExpressionValidator. Once I leave the text box, it immediately fires the validator. But upon clicking on any button (causes to generate postback) removes the regular expression validators error display from the screen. How can I retrigger the client validation?

I am a newbie with asp.net

---------------------------
|                         | * Invalid input
---------------------------

Listbox A           Listbox B
------------       ------------
|          |       |          |
|          |       |          |
|          |   >>  |          |
|          |       |          |
|          |       |          |
------------       ------------

Code goes like this.

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:TextBox ID="nameBox" runat="server" CssClass="StandardTextBox" Width="297px"
        EnableViewState="true"></asp:TextBox>
    <asp:RegularExpressionValidator ID="regExpValidatorRuleName2" align="left" runat="server"
        ControlToValidate="nameBox" 
        Width="10px" Height="10px" 
        CssClass="StandardErrorLabel"
        Display="Dynamic" 
        ErrorMessage="Input has Invalid character(s). Valid characters are a-z, A-Z, 0-9, _, @, ., -"
        ValidationGroup="EditingPanel" 
        ValidationExpression="^[[email protected]]*$" 
        ToolTip="Input has Invalid character(s). Valid characters are a-z, A-Z, 0-9, _, @, ., -">*</asp:RegularExpressionValidator>
    <asp:Panel ID="criteriaPanel1" GroupingText="Test" runat="server"
        left="19px" CssClass="InputPanelTableLeft" Width="400px" Height="470px" Font-Bold="True"
        Font-Size="X-Small">
        <table class="InputPanelTable">
            <tr>
                <td align="left">
                    <asp:ListBox ID="listboxA" Rows="10" runat="server" EnableViewState="true"
                        Width="150px" Height="100px"></asp:ListBox>
                </td>
                <td style="padding: 0px 5px 0px 5px" valign="middle">
                    <asp:Button ID="buttonMove" runat="server" OnClick="buttonMove_OnClick"
                        Text="&gt;&gt;" ToolTip="Moves selected item from left side to right" />
                </td>
                <td align="left">
                    <asp:ListBox ID="listboxB" Rows="10" runat="server" EnableViewState="true"
                        Width="150px" Height="100px"></asp:ListBox>
                </td>
            </tr>
        </table>
    </asp:Panel>
</asp:Content>
1

1 Answers

1
votes

I found that buttonMove is causing postback when clicked on it.

Validation controls' error messages cannot persist uding postbacks.

You have not mentioned what to move from ListBox A to ListBox B.

Hence, if you can move elements from ListBox A to ListBox B using JavaScript (I mean, don't use serverside program), your problem can be solved.

Please let me know if you have any problems.