Вопрос

I have a aspx page in which i have putted two update panel with two submit buttons one in each...But on clicking second button it is not firing second button event it is taking first button validate message..

Here is my aspx page code....

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updDate1" runat="server" UpdateMode="Conditional" style="position: absolute;
    left: 0px; top: 0px; width: 339px; height: 243px;">
    <ContentTemplate>
        <table width="400">
            <tr>
                <td>
                </td>
                <td colspan="2">
                    <b>Sign Up for New User Account</b>
                </td>
            </tr>
            <tr>
                <td>
                    UserName:
                </td>
                <td>
                    <asp:TextBox ID="txtUserName" runat="server" />
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="rqfUserName" runat="server" ControlToValidate="txtUserName"
                        Display="Dynamic" ErrorMessage="Required" ForeColor="Red" />
                </td>
            </tr>
            <tr>
                <td>
                    Password:
                </td>
                <td>
                    <asp:TextBox ID="txtPwd" runat="server" TextMode="Password" />
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtPwd"
                        Display="Dynamic" ErrorMessage="Required" ForeColor="Red" />
                </td>
            </tr>
            <tr>
                <td>
                    Confirm Password:
                </td>
                <td>
                    <asp:TextBox ID="txtCnfPwd" runat="server" TextMode="Password" />
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="PasswordConfirmRequiredValidator" runat="server"
                        ControlToValidate="txtCnfPwd" ForeColor="red" Display="Dynamic" ErrorMessage="Required" />
                    <asp:CompareValidator ID="PasswordConfirmCompareValidator" runat="server" ControlToValidate="txtCnfPwd"
                        ForeColor="red" Display="Dynamic" ControlToCompare="txtPwd" ErrorMessage="Confirm password must match password." />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Create User" />
                </td>
                <tr>
                    <td class="style1" colspan="3">
                        <asp:Label ID="lblResult" runat="server" Font-Bold="true" />
                    </td>
                </tr>
            </tr>
        </table>
    </ContentTemplate>
</asp:UpdatePanel>
<div>
    <asp:UpdatePanel ID="updDate2" runat="server" UpdateMode="Conditional" RenderMode="Inline"
        style="position: absolute; left: 628px; top: 0px; width: 339px; height: 243px;">
        <ContentTemplate>
            <div class="GridviewDiv">
                <table>
                    <tr>
                        <td align="right">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:GridView ID="gvRoles" runat="server" CssClass="Gridview" AutoGenerateColumns="false">
                                <HeaderStyle BackColor="#df5015" />
                                <Columns>
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkRole" runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Role Name">
                                        <ItemTemplate>
                                            <asp:Label ID="lblRole" runat="server" Text="<%#Container.DataItem %>" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Button ID="btnAssign" runat="server" Text="Assign or UnAssign" OnClick="btnAssign_Click"
                                Style="height: 26px" />
                        </td>
                    </tr>
                </table>
                <div>
                    <asp:Label ID="lblSuccess" runat="server" Font-Bold="true" />
                    <br />
                    <asp:Label ID="lblError" runat="server" Font-Bold="true" />
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>
</form>

Any help will be highly apprecited..

Thanks In advance..

Это было полезно?

Решение

Dear i tried your code by Making dummy project and it clearly tells me that it's a problem of CausesValidation="false",I know you tried this thing as well but even i don't know your back end coding.So same suggesstion from my side just change your btnAssign like

<asp:Button ID="btnAssign" runat="server" Text="Assign or UnAssign" 
Style="height: 26px" onclick="btnAssign_Click" CausesValidation="false" />

Note :- Try to check it in different browser as well.

Also try for ValidationGroup as well. Apply ValidationGroup property into your validation control and also assign that same property to btnSubmit.This will work.

Hope it works.

Другие советы

Set CausesValidation="false" in the second button

Setting CausesValidation="false" in the second button should have worked.

One another way to get this work is to assign a common ValidationGroup to your Validators as well as to your first Submit button [only of UpdatePanel updDate1 ].

For e.g. in your Validators:

<asp:RequiredFieldValidator ID="rqfUserName" runat="server"
     ControlToValidate="txtUserName"Display="Dynamic"
     ErrorMessage="Required" ForeColor="Red"
     ValidationGroup="updDate1UserCreation" />

And your submit button with ID:btnSubmit

<asp:Button ID="btnSubmit" runat="server"
     OnClick="btnSubmit_Click" Text="Create User"
     ValidationGroup="updDate1UserCreation" />

Your first updatePanel will finally look like:

<asp:UpdatePanel ID="updDate1" runat="server" UpdateMode="Conditional"
    style="position: absolute;
    left: 0px; top: 0px; width: 339px; height: 243px;">
    <ContentTemplate>
        <table width="400">
            <tr>
                <td>
                </td>
                <td colspan="2">
                    <b>Sign Up for New User Account</b>
                </td>
            </tr>
            <tr>
                <td>
                    UserName:
                </td>
                <td>
                    <asp:TextBox ID="txtUserName" runat="server" />
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="rqfUserName" runat="server"
                         ControlToValidate="txtUserName"
                         Display="Dynamic" ErrorMessage="Required" ForeColor="Red"
                         ValidationGroup="updDate1UserCreation" />
                </td>
            </tr>
            <tr>
                <td>
                    Password:
                </td>
                <td>
                    <asp:TextBox ID="txtPwd" runat="server" TextMode="Password" />
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
                         runat="server" ControlToValidate="txtPwd"
                         Display="Dynamic" ErrorMessage="Required" ForeColor="Red"
                         ValidationGroup="updDate1UserCreation" />
                </td>
            </tr>
            <tr>
                <td>
                    Confirm Password:
                </td>
                <td>
                    <asp:TextBox ID="txtCnfPwd" runat="server" TextMode="Password" />
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="PasswordConfirmRequiredValidator"
                           runat="server"
                           ControlToValidate="txtCnfPwd" ForeColor="red" 
                           Display="Dynamic" ErrorMessage="Required"
                           ValidationGroup="updDate1UserCreation" />
                    <asp:CompareValidator ID="PasswordConfirmCompareValidator"
                         runat="server" ControlToValidate="txtCnfPwd"
                         ForeColor="red" Display="Dynamic" ControlToCompare="txtPwd"
                         ErrorMessage="Confirm password must match password."
                         ValidationGroup="updDate1UserCreation" />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="btnSubmit" runat="server"
                         OnClick="btnSubmit_Click" Text="Create User"
                         ValidationGroup="updDate1UserCreation" />
                </td>
                <tr>
                    <td class="style1" colspan="3">
                        <asp:Label ID="lblResult" runat="server" Font-Bold="true" />
                    </td>
                </tr>
            </tr>
        </table>
    </ContentTemplate>

</asp:UpdatePanel>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top