如何在asp.net页面中使用多个Scriptmanagers

时间:2015-11-25 05:45:04

标签: c# jquery asp.net ajax asp.net-ajax

我有一个对话框,用户注册和登录都在asp.net ajax(脚本管理器)中。我对所有输入都使用了asp.net字段验证。当我尝试登录时也要求输入注册表单的输入。如何将这两个东西分开并使用asp.net ajax。任何建议或帮助都非常感谢。 TIA

<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div class="sidebar js-sidebar-aside">
            <div class="sidebar__wrapper">
                <div class="sidebar__close js-toggle-sidebar visible-xs">
                    <span class="oi oi-x"></span>
                </div>
                <div class="sidebar__form form_alt">
                    <div class="form-group">
                        <label class="sr-only" for="login__username">
                            Username</label>
                        <asp:TextBox type="text" class="form-control" runat="server" ID="txtUserName" placeholder="Username"></asp:TextBox>
                        <asp:RequiredFieldValidator runat="server" CssClass="sidebar__heading" ID="reqName"
                            Display="Dynamic" ControlToValidate="txtUserName" ErrorMessage="Please enter your name!" />
                    </div>
                    <div class="form-group">
                        <label class="sr-only" for="login__password">
                            Password</label>
                        <asp:TextBox type="password" class="form-control" runat="server" ID="txtPassword"
                            placeholder="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator runat="server" CssClass="sidebar__heading" ID="RequiredFieldValidator1"
                            Display="Dynamic" ControlToValidate="txtUserName" ErrorMessage="Please enter Password!" />
                    </div>
                    <asp:Button runat="server" type="submit" class="btn btn-block btn-primary" UseSubmitBehavior="false"
                        ID="btnSignIn" Text="Sign In" OnClick="btnSignIn_Click"></asp:Button>
                    <asp:Label ID="Label1" class="sidebar__heading" runat="server" Text=""></asp:Label>
                </div>
                <h4 class="sidebar__heading">
                    Didn't invite anyone?
                </h4>
                <ul class="sidebar__menu">
                    <li><a href="#">Sign Up</a></li>
                </ul>
                <div class="sidebar__form form_alt">
                    <div class="form-group">
                        <label class="sr-only" for="login__username">
                            Email</label>
                        <asp:TextBox type="text" runat="server" class="form-control" ID="txtSignUpEmail"
                            placeholder="Email"></asp:TextBox>
                        <asp:RequiredFieldValidator runat="server" CssClass="sidebar__heading" ID="RequiredFieldValidator2"
                            Display="Dynamic" ControlToValidate="txtSignUpEmail" ErrorMessage="Please enter your Emial!" />
                        <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Please Enter Valid Email ID"
                            ValidationGroup="vgSubmit" ControlToValidate="txtSignUpEmail" CssClass="sidebar__heading"
                            Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
                        </asp:RegularExpressionValidator>
                    </div>
                    <div class="form-group">
                        <label class="sr-only" for="login__username">
                            Username</label>
                        <asp:TextBox type="text" runat="server" class="form-control" ID="txtSignUpUserName"
                            placeholder="Username"></asp:TextBox>
                        <asp:RequiredFieldValidator runat="server" CssClass="sidebar__heading" ID="RequiredFieldValidator3"
                            Display="Dynamic" ControlToValidate="txtSignUpUserName" ErrorMessage="Please enter your Username!" />
                    </div>
                    <div class="form-group">
                        <label class="sr-only" for="login__password">
                            Password</label>
                        <asp:TextBox type="password" runat="server" class="form-control" ID="txtSignUpPassword"
                            placeholder="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator runat="server" CssClass="sidebar__heading" ID="RequiredFieldValidator4"
                            Display="Dynamic" ControlToValidate="txtSignUpPassword" ErrorMessage="Please enter your password!" />
                        <asp:RegularExpressionValidator ID="RegExp1" runat="server" ErrorMessage="Password length must be between 7 to 10 characters"
                            ControlToValidate="txtSignUpPassword" CssClass="sidebar__heading" Display="Dynamic"
                            ValidationExpression="^[a-zA-Z]{7,10}$" />
                    </div>
                    <div class="form-group">
                        <label class="sr-only" for="login__password">
                            Repeat Password</label>
                        <asp:TextBox type="password" runat="server" class="form-control" ID="txtSignUpRepeatPassword"
                            placeholder="Repeat Password"></asp:TextBox>
                        <asp:RequiredFieldValidator runat="server" CssClass="sidebar__heading" ID="RequiredFieldValidator5"
                            Display="Dynamic" ControlToValidate="txtSignUpRepeatPassword" ErrorMessage="Please enter your RepeatPassword!" />
                        <asp:CompareValidator runat="server" ID="Comp1" ControlToValidate="txtSignUpPassword"
                            CssClass="sidebar__heading" Display="Dynamic" ControlToCompare="txtSignUpRepeatPassword"
                            Text="Password mismatch" />
                    </div>
                    <asp:Button runat="server" ID="btnSignUp" class="btn btn-block btn-primary" Text="Sign UP"
                        OnClick="btnSignup_Click"></asp:Button>
                    <asp:Label ID="Label2" class="sidebar__heading" runat="server" Text=""></asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>

1 个答案:

答案 0 :(得分:0)

您可能面临此问题,因为您尚未将ValidationGroup设置为两个按钮。

你去吧

<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div class="sidebar js-sidebar-aside">
            <div class="sidebar__wrapper">
                <div class="sidebar__close js-toggle-sidebar visible-xs">
                    <span class="oi oi-x"></span>
                </div>
                <div class="sidebar__form form_alt">
                    <div class="form-group">
                        <label class="sr-only" for="login__username">
                            Username</label>
                        <asp:TextBox type="text" class="form-control" runat="server" ID="txtUserName" placeholder="Username"
                            ValidationGroup="SignIn"></asp:TextBox>
                        <asp:RequiredFieldValidator runat="server" CssClass="sidebar__heading" ID="reqName"
                            Display="Dynamic" ControlToValidate="txtUserName" ValidationGroup="SignIn" ErrorMessage="Please enter your name!" />
                    </div>
                    <div class="form-group">
                        <label class="sr-only" for="login__password">
                            Password</label>
                        <asp:TextBox type="password" ValidationGroup="SignIn" class="form-control" runat="server"
                            ID="txtPassword" placeholder="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ValidationGroup="SignIn" runat="server" CssClass="sidebar__heading"
                            ID="RequiredFieldValidator1" Display="Dynamic" ControlToValidate="txtUserName"
                            ErrorMessage="Please enter Password!" />
                    </div>
                    <asp:Button runat="server" type="submit" ValidationGroup="SignIn" class="btn btn-block btn-primary"
                        UseSubmitBehavior="false" ID="btnSignIn" Text="Sign In" OnClick="btnSignIn_Click">
                    </asp:Button>
                    <asp:Label ID="Label1" class="sidebar__heading" runat="server" Text=""></asp:Label>
                </div>
                <h4 class="sidebar__heading">
                    Didn't invite anyone?
                </h4>
                <ul class="sidebar__menu">
                    <li><a href="#">Sign Up</a></li>
                </ul>
                <div class="sidebar__form form_alt">
                    <div class="form-group">
                        <label class="sr-only" for="login__username">
                            Email</label>
                        <asp:TextBox type="text" ValidationGroup="vgSubmit" runat="server" class="form-control"
                            ID="txtSignUpEmail" placeholder="Email"></asp:TextBox>
                        <asp:RequiredFieldValidator ValidationGroup="vgSubmit" runat="server" CssClass="sidebar__heading"
                            ID="RequiredFieldValidator2" Display="Dynamic" ControlToValidate="txtSignUpEmail"
                            ErrorMessage="Please enter your Emial!" />
                        <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Please Enter Valid Email ID"
                            ValidationGroup="vgSubmit" ControlToValidate="txtSignUpEmail" CssClass="sidebar__heading"
                            Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
                        </asp:RegularExpressionValidator>
                    </div>
                    <div class="form-group">
                        <label class="sr-only" for="login__username">
                            Username</label>
                        <asp:TextBox type="text" ValidationGroup="vgSubmit" runat="server" class="form-control"
                            ID="txtSignUpUserName" placeholder="Username"></asp:TextBox>
                        <asp:RequiredFieldValidator runat="server" CssClass="sidebar__heading" ID="RequiredFieldValidator3"
                            Display="Dynamic" ValidationGroup="vgSubmit" ControlToValidate="txtSignUpUserName"
                            ErrorMessage="Please enter your Username!" />
                    </div>
                    <div class="form-group">
                        <label class="sr-only" for="login__password">
                            Password</label>
                        <asp:TextBox type="password" ValidationGroup="vgSubmit" runat="server" class="form-control"
                            ID="txtSignUpPassword" placeholder="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ValidationGroup="vgSubmit" runat="server" CssClass="sidebar__heading"
                            ID="RequiredFieldValidator4" Display="Dynamic" ControlToValidate="txtSignUpPassword"
                            ErrorMessage="Please enter your password!" />
                        <asp:RegularExpressionValidator ID="RegExp1" ValidationGroup="vgSubmit" runat="server"
                            ErrorMessage="Password length must be between 7 to 10 characters" ControlToValidate="txtSignUpPassword"
                            CssClass="sidebar__heading" Display="Dynamic" ValidationExpression="^[a-zA-Z]{7,10}$" />
                    </div>
                    <div class="form-group">
                        <label class="sr-only" for="login__password">
                            Repeat Password</label>
                        <asp:TextBox type="password" ValidationGroup="vgSubmit" runat="server" class="form-control"
                            ID="txtSignUpRepeatPassword" placeholder="Repeat Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ValidationGroup="vgSubmit" runat="server" CssClass="sidebar__heading"
                            ID="RequiredFieldValidator5" Display="Dynamic" ControlToValidate="txtSignUpRepeatPassword"
                            ErrorMessage="Please enter your RepeatPassword!" />
                        <asp:CompareValidator ValidationGroup="vgSubmit" runat="server" ID="Comp1" ControlToValidate="txtSignUpPassword"
                            CssClass="sidebar__heading" Display="Dynamic" ControlToCompare="txtSignUpRepeatPassword"
                            Text="Password mismatch" />
                    </div>
                    <asp:Button runat="server" ID="btnSignUp" class="btn btn-block btn-primary" Text="Sign UP"
                        OnClick="btnSignup_Click" ValidationGroup="vgSubmit"></asp:Button>
                    <asp:Label ID="Label2" class="sidebar__heading" runat="server" Text=""></asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>