0

net application. With this application a user can add a guestconnection for a time. for this i have a button that open a modal dialog who a user can add a guest. the input must be a firstname,lastname,company and the time. i use the validation controls and a ValidationGroup. The Validationcontrols check if I forget a input but if I click on "add" the code doesn't run. I try this with a simple div but the same method:

Here is my aspx code:

<div id="add">

                    <div id="Div2" class="popupConfirmation" runat="server" style="width:350px; height:290px;">

                          <div class="bodycontrol">
                            <table>  
                        <tr>
                            <td><asp:Label ID="Label3" runat="server" Text="Vorname"></asp:Label></td>
                            <td><asp:TextBox ID="TextBox1" runat="server" ValidationGroup="valid" ></asp:TextBox></td>
                            <td><asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="valid" runat="server" ForeColor="red" ErrorMessage="*" ControlToValidate="TextBox1"></asp:RequiredFieldValidator></td>
                        </tr>
                        <tr>
                            <td><asp:Label ID="Label4" runat="server" Text="Nachname"></asp:Label></td>
                            <td><asp:TextBox ID="TextBox2" runat="server" ValidationGroup="valid"></asp:TextBox></td>
                            <td><asp:RequiredFieldValidator ID="RequiredFieldValidator2" ValidationGroup="valid" runat="server" ForeColor="red" ErrorMessage="*" ControlToValidate="TextBox2"></asp:RequiredFieldValidator></td>
                        </tr>
                        <tr>
                            <td><asp:Label ID="Label5" runat="server" Text="Firma"></asp:Label></td>
                            <td><asp:TextBox ID="TextBox3" runat="server" ValidationGroup="valid"></asp:TextBox></td>
                            <td><asp:RequiredFieldValidator ID="RequiredFieldValidator3" ValidationGroup="valid" runat="server" ForeColor="red" ErrorMessage="*" ControlToValidate="TextBox3"></asp:RequiredFieldValidator></td>
                        </tr>
                    </table>
                           <br />
                            <table>
                        <tr>
                            <td><asp:LinkButton ID="LinkButton1" runat="server" class="GuestButtons"  Text="Hinzufügen" ValidationGroup="valid" onclick="btn_GuestListViewAddDialog_YES_Click" ></asp:LinkButton></td>
                            <td><asp:LinkButton ID="LinkButton2" runat="server" class="GuestButtons" Text="Abbrechen" ValidationGroup="never"></asp:LinkButton></td>
                        </tr>
                    </table>
                           <br />
                            <table>
                        <tr>
                            <td><asp:Label ID="Label10" runat="server" Text="*Bitte alle Felder ausfüllen"></asp:Label></td>
                        </tr>
                    </table>
                          </div>

                    </div>          

               </div>

here is my c# code:

   protected void btn_GuestListViewAddDialog_YES_Click(object sender, EventArgs e)
            {
                if (Page.IsValid) //Here i make a breakpoit but it doesn't use this code :( 
                {

    ...//here is my code

}

}

this is in my script block if i click on the linkbutton:

WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$lw_content$LinkButton1", "", true, "valid", "", false, true))

1 Answer 1

1

If you want to force validation on serverside you need to call Page.Validate() before you check Page.IsValid.

protected void btn_GuestListViewAddDialog_YES_Click(object sender, EventArgs e)
{
    Page.Validate();
    if (Page.IsValid) 
    {

The LinkButton must also have a ValidationGroup, the same valid-group if you want to validate this group if the link-button was clicked or a different group if you don't want to trigger validation.

Edit: However, Page.Validate should be redundant since CausesValidation is true by default for a LinkButton and you have specified also a ValidationGroup for it. So i'm at a loss.

1
  • I add Page.Validation() and my LinkButton have a validationGroup but It doesn't work :(
    – Tarasov
    Oct 29, 2013 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.