4

I'm currently searching for a way to prevent multiple form submits in ASP.NET (i.e. the user clicks on a submitbutton several times, causing the OnClick-Event to fire several times also).

Currently, I'm doing it like this:

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        Page.ClientScript.RegisterOnSubmitStatement(GetType(), "ServerForm",
        "if (this.submitted) return false; this.submitted = true; return true;");
    }

This works like a charm for synchronous postbacks - the 'submitted'-value will be reset after each postback and prevent the form from being submitted multiple times in the same run - however, this method does not work for AsyncPostbacks i.e. with an UpdatePanel, so now I'm searching for an idea to make this happen without having to dis- and enable each and every button via JS after clicking a button.

Thanks,

Dennis

Dennis Röttger
  • 1,975
  • 6
  • 32
  • 51
  • Because it's an awful lot of JS that I really don't want in my pages, additionally it has to work for several Browsers (hi IE), which really can be a pain to implement, I was hoping to find a simple solution such as this that I can just implement in a class deriving from Page. – Dennis Röttger Mar 09 '12 at 10:39

4 Answers4

4

You can use Page.get_isInAsyncPostBack() in javascript to check the state of async request.

Refer this link for more information: http://ranaictiu-technicalblog.blogspot.com/2009/03/prevent-concurrent-asynchronous.html

Hoa Tran
  • 271
  • 2
  • 6
1

why not you check in your database ? if the user already registerd then give a alert box. and you can also check PRG pattern

Handling Form submission with PRG

Community
  • 1
  • 1
Ravi Gadag
  • 15,735
  • 5
  • 57
  • 83
0

Hopes this will help you.

http://www.techimo.com/forum/webmastering-programming/210441-prevent-multiple-postbacks-javascript-net.html

PraveenVenu
  • 8,217
  • 4
  • 30
  • 39
  • 2
    Welcome to Stack Overflow! While this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Bill the Lizard Mar 09 '12 at 12:11
0
  1. You can check the start & end methods present in classSys.WebForms.PageRequestManager to check for ASync requests.
  2. Sys.WebForms.PageRequestManager You can modify the code in above example & disable the button by using simple javascript like

    document.getElementById("YouButton.ClientID").disabled = true;

Zo Has
  • 12,599
  • 22
  • 87
  • 149