表单提交浏览器刷新

时间:2012-03-25 18:41:14

标签: c# asp.net form-submit

我无法找到解决方案,点击浏览器的刷新按钮停止表单提交。

这是我的登录表单:

<asp:Login ID="EMSLogin" runat="server" OnAuthenticate="EMSLogin_Authenticate">
    <LayoutTemplate>
        <asp:Panel ID="Panel1" runat="server" CssClass="wrapper">
            <asp:Panel ID="Panel2" runat="server" CssClass="holder">
                <asp:Panel ID="Panel3" runat="server" CssClass="loginBox one_edge_shadow">
                    <h1>
                        Login Credentials</h1>
                    <asp:Panel ID="Panel4" runat="server" CssClass="name topmargin">
                        <asp:Panel ID="Panel5" runat="server" CssClass="label">
                            <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
                        </asp:Panel>
                        <asp:Panel ID="Panel6" runat="server" CssClass="textBox">
                            <telerik:RadTextBox ID="UserName" runat="server" Height="16px" Width="165px" Font-Size="14px"
                                Font-Names="Arial Sans-Serif" ToolTip="Enter your valid login name" />
                            <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
                                ValidationGroup="EMSLogin">*</asp:RequiredFieldValidator>
                        </asp:Panel>
                        <br class="clearfix" />
                    </asp:Panel>
                    <asp:Panel ID="Panel7" runat="server" CssClass="name topmargin">
                        <asp:Panel ID="Panel8" runat="server" CssClass="label">
                            <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                        </asp:Panel>
                        <asp:Panel ID="Panel9" runat="server" CssClass="textBox">
                            <telerik:RadTextBox ID="Password" runat="server" TextMode="Password" Height="16px"
                                Width="165px" Font-Size="14px" Font-Names="Arial Sans-Serif" ToolTip="Enter your valid password" />
                            <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
                                ValidationGroup="EMSLogin">*</asp:RequiredFieldValidator>
                        </asp:Panel>
                        <br class="clearfix" />
                        <telerik:RadButton ID="LoginButton" runat="server" CommandName="Login" Text="Log In"
                            CssClass="loginButton" Font-Size="14px" Width="100px" ValidationGroup="EMSLogin"
                            ToolTip="Click to log in" />
                    </asp:Panel>
                </asp:Panel>
            </asp:Panel>
        </asp:Panel>
    </LayoutTemplate>
</asp:Login>

在后端:

protected void Page_Load(object sender, EventArgs eventArgs) {
    log.Info("=============INSIDE Page_Load======");
    DataBind();
    LoginErrorWindow.VisibleOnPageLoad = false;     
}

protected void EMSLogin_Authenticate(object sender, AuthenticateEventArgs e) {
    log.Info("=============INSIDE EMSLogin_Authenticate======");
    RadTextBox UserName = EMSLogin.FindControl("UserName") as RadTextBox;
    RadTextBox Password = EMSLogin.FindControl("Password") as RadTextBox;

    if (Membership.ValidateUser(UserName.Text, Password.Text)) {
    FormsAuthentication.RedirectFromLoginPage(UserName.Text, false);
    } else {
    LoginErrorWindow.NavigateUrl = EMSApplication.Web.Utils.NavigationUtils.GetLoginErrorDialogURL();
    LoginErrorWindow.VisibleOnPageLoad = true;
    }
}

现在,如果我按下刷新按钮,一次登录失败后,方法EMSLogin_Authenticate再次执行。在重新加载之前,它显示:

enter image description here

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

登录失败后,在错误页面上Response.Redirect

请参阅维基百科上的PRG pattern

  

Post / Redirect / Get(PRG)是一种Web开发设计模式,可以防止一些重复的表单提交,为用户代理(用户)创建更直观的界面。 PRG以可预测的方式实现书签和刷新按钮,不会创建重复的表单提交。