1

I have a textbox and a button control in a panel which is in update panel. I want to validate textbox if it is empty on button click. Actually this panel is using for Modal Popup Extender functionality. For pop up I am using AJAX modal popup extender control.

I am using Requiredfieldvalidator control to validate textbox but it is not firing on button click.

Code:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
       <ContentTemplate>
            <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none">
                <asp:TextBox ID="TextBox1" runat="server" Visible="false" CausesValidation="true"></asp:TextBox>

                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2" ControlToValidate="TextBox1"
                                                                    ErrorMessage="Data is Required">
                    </asp:RequiredFieldValidator>
                <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="btnSubmit_Click" CausesValidation="true" />
             </asp:Panel>
     </ContentTemplate>
    <Triggers>

       <asp:AsyncPostBackTrigger ControlID="Button1" />
    </Triggers>
</asp:UpdatePanel>

Any solution?

Edit

<cc1:ModalPopupExtender ID="mpePopUp" runat="server" DropShadow="false" PopupControlID="Panel1"
                                        TargetControlID="lnkFake" BackgroundCssClass="modalBackground">
                                    </cc1:ModalPopupExtender>

Code behind: I have link button in gridview.. clicking on that link the popup should be dislpayed. In gridview row command event I am using popup show method

mpePopUp.show();

Srikanth
  • 683
  • 3
  • 16
  • 23
  • Can you provide us with more code? I have use your code exactly and cannot reproduce the error. – Conrad Lotz Jul 27 '12 at 06:09
  • @JLC007 You are correct. It is working for updatepanel but when I am using same panel in AJAX popup extender the same is not working. I added code for that in my question as per your request – Srikanth Jul 27 '12 at 07:06

1 Answers1

0

add validation group and remove cause validation from text box try it

<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none">
                <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>

                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2" ControlToValidate="TextBox1" validationgroup="Group1" ErrorMessage="Data is Required">
                    </asp:RequiredFieldValidator>
                <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="btnSubmit_Click" validationgroup="UserInfoGroup"  CausesValidation="true" />
             </asp:Panel>
COLD TOLD
  • 13,513
  • 3
  • 35
  • 52