1

I have a register.aspx which takes some information from user and stores it in the database. However, I cannot solve the double submit problem when user refreshes the page. Here is my registration.aspx file:

<form id="form1" runat="server">
     <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>

     <asp:Button ID="btnRegister" runat="server" Text="Button" onclick="RegisterUser" />

     <asp:Label ID="lblErrorMessage" runat="server" Text=""></asp:Label>
</form>

And here is the registration.aspx.cs file:

protected void RegisterUser(object sender, EventArgs e)
{
    if (txtUserName.Text.Length < 3)
    {
        lblErrorMessage.Text = "username should be minimum 3 characters, try again.";
    }
}

However, I try to test it using my browser, chrome. When I use the text "a" for the username, it goes into the RegisterUser function and shows the error message. But sadly, when I try to refresh the page it asks for resubmission while I was expecting to refresh without any problem:

enter image description here

I tried using Response.Redirect and it didn't work either.

4

2 回答 2

0

I tried an easy way for you using UpdatePanel and Template:

change the code in your main page like this:

<form id="form1" runat="server" >

  <asp:UpdatePanel runat="server"><ContentTemplate>
     <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
     <asp:Button ID="btnRegister" runat="server" Text="Button" onclick="RegisterUser" />
     <asp:Label ID="lblErrorMessage" runat="server" Text=""></asp:Label>
     <asp:ScriptManager ID="ScriptManager1" runat="server">
     </asp:ScriptManager>
     </ContentTemplate>
  </asp:UpdatePanel>
</form>

I think that will solve your problem in an easier way. Let me know if you have any problem with it.

于 2013-03-30T20:17:08.290 回答
0

please set causesvalidation="false" in your TextBox and button control

for try below code

<asp:TextBox ID="txtUserName" CausesValidation="false" runat="server"></asp:TextBox>
        <asp:Button ID="btnRegister"  CausesValidation="false" runat="server" Text="Button" onclick="RegisterUser" />
于 2013-03-30T20:32:23.560 回答