Div is not hidden after calling Page_ClientValidate

The following code does not hide the "info" DIV and show the "questions" DIV when Page_ClientValidate is called sets isValid to true. If I set isValid to true or false, it works as expected. Why does Page_ClientValidate prevent the hide/show behaviour to occur?

function hide() {
        var isValid = Page_ClientValidate('validInfo');
        if (isValid) {
            if (!$('[id$=chkConfirm]').is(':checked'))
            { alert("Please confirm and agree with conditions"); }
            else {
                $('#info').hide();
                $('#questions').show();
            }
        }
    }    

Here is the HTML - I shortened it to the main parts and there are only some more txtBoxes and radioLists in the DIVS:

 <div id="info">
    <asp:TextBox ID="tBoxTradingName" runat="server" Width="200"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tBoxTradingName"
        ValidationGroup="validInfo">Required</asp:RequiredFieldValidator>
    <asp:CheckBox ID="chkConfirm" Text=" I confirm that the information provided above is accurate."
        runat="server" />
    <asp:Button ID="btnNext" Text="Next >>" runat="server" OnClientClick="hide()" Width="100"
        CausesValidation="true" ValidationGroup="validInfo" />
</div>
<div id="questions" style="display:none;">
    <div class="label">
        Do you trade as a
    </div>
    <asp:RadioButtonList ID="rBtnTradeAs" runat="server">
        <asp:ListItem>Sole Proprietor</asp:ListItem>
        <asp:ListItem>Company</asp:ListItem>
        <asp:ListItem>Closed Corporation</asp:ListItem>
        <asp:ListItem>Trust</asp:ListItem>
        <asp:ListItem>Other (please specify)</asp:ListItem>
    </asp:RadioButtonList>
    <asp:TextBox ID="txtBoxTradeAs" runat="server" Width="200"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator30" runat="server" ControlToValidate="rBtnTradeAs"
        ErrorMessage="Required">
    </asp:RequiredFieldValidator>
</div>

Answers


You're calling a clientside function on a Button's OnCLientClick. Then you want to change visibility of some controls via javascript if Page_ClientValidate returns true.

The problem is: the button will cause a postback if no Validator bites. The postback will cause the page to be recreated on serverside so that every clientside change is lost.

So either

  • don't postback (returning false from OnCLientClick will prevent a postback) or
  • change visibility of the controls on serverside(by adding runat="server" to your divs)

Need Your Help

Why can't I compute a correct HMAC signature?

google-apps-script

I am trying to compute an HMAC signature in Google Apps Script, but the documentation isn't 100% clear on how I need to pass in the parameters, and I have been unable to get the expected output.

How to receive sms on my ios app (workaround)?

ios sms message

I know i can't access the sms database of a ios device, but there's no workaround to achieve the same task using other tools?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.