1
votes

I have a div with 3 text box fields on it where i am using
asp:RequiredFieldValidator and asp:CompareValidator

on change password button click the div getting visible

protected void btnPass_Click(object sender, EventArgs e)
    {
        chngPwd.Visible = true;
    }

and on the button cancel visible property set to false but its not going invisible.

 protected void btnCancel_Click(object sender, EventArgs e)
    {
        chngPwd.Visible = false;
    }

This is my page showing the error on cancel button press.

ASP code is as follows

   <div runat="server" id="chngPwd" visible="false" style="margin-left: 40px">
        <div>
            <div class="col-md-4"></div>
            <div class="col-md-8">
                <asp:Label ID="lblOldP" runat="server" Text="Old Password: -"></asp:Label>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="txtOldP" runat="server" TextMode="Password" Width="149" Height="33px"></asp:TextBox>
            </div>
            <br />
            <br />
        </div>
        <div>
            <div class="col-md-4"></div>
            <div class="col-md-8">
                <asp:RequiredFieldValidator runat="server" ControlToValidate="txtOldP" CssClass="text-danger" ErrorMessage="The Old Password field is required." />
                <br />
            </div>
        </div>
        <br />

        <div>
            <div class="col-md-4"></div>
            <div class="col-md-8">
                <asp:Label ID="lblNewP" runat="server" Text="New Password: -"></asp:Label>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="txtNewP" runat="server" TextMode="Password" Width="149" Height="33px"></asp:TextBox>
            </div>
            <br />
            <br />
        </div>
        <div>
            <div class="col-md-4"></div>
            <div class="col-md-8">
                <asp:RequiredFieldValidator runat="server" ControlToValidate="txtNewP" CssClass="text-danger" ErrorMessage="The New Password field is required." />
                <br />
            </div>
        </div>
        <br />
        <div>
            <div class="col-md-4"></div>
            <div class="col-md-8">
                <asp:Label ID="lblRNewP" runat="server" Text="Confirm New Password: -"></asp:Label>&nbsp;&nbsp;
            <asp:TextBox ID="txtRNewP" runat="server" TextMode="Password" Width="149" Height="33px"></asp:TextBox>
            </div>
            <br />
            <br />
        </div>
        <div>
            <div class="col-md-4"></div>
            <div class="col-md-8">
                <asp:RequiredFieldValidator runat="server" ControlToValidate="txtRNewP" CssClass="text-danger" ErrorMessage="The Confirm New Password field is required." />
                <br />
                <asp:CompareValidator runat="server" ControlToCompare="txtNewP" ControlToValidate="txtRNewP" CssClass="text-danger" ErrorMessage="The Password doesn't match." />
                <br />
            </div>
        </div>
        <br />
        <div>
            <div class="col-md-8"></div>
            <div class="col-md-4">
                <asp:Button ID="btnSbmt" runat="server" Text="Submit" OnClick="btnChngP_Click" />
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" />
            </div>
        </div>
        <br />
        <br />

 <div>
1
Can we see the asp you're usingKratosMafia
Added the asp code in my question itself. please.Black Canery
well your last div should be /divKratosMafia

1 Answers

3
votes

So your issue here is the validators are working as intended. The btnclick is going off but not calling because you have a validator. If you enter in the information and then hit cancel the div will hide. But you have It set to not run anything unless those textboxes are filled.

So we will change this

<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" />

to this

<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" CausesValidation="false"/>