Prevent submitting multiple forms in ASP.NET

I'm currently looking for a way to prevent multiple forms from appearing in ASP.NET (i.e. the user clicks the submitbutton button several times, also raises the OnClick-Event).

I am currently doing 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 does not allow the form to be submitted several times in one run β€” however this method does not work for AsyncPostbacks, i.e. with UpdatePanel, so now I'm looking for an idea to do this without having to disable each button via JS after the button is clicked.

Thanks,

Dennis

+4
source share
4 answers

You can use page.get_isInAsyncPostBack () in javascript to check the status of the async request.

For more information, see this link: http://ranaictiu-technicalblog.blogspot.com/2009/03/prevent-concurrent-asynchronous.html

+4
source

why don't you check your database? if the user has already registered, give a warning field. and you can also check the PRG template

Processing form submission using PRG

+1
source
  • You can check the start and end methods present in the Sys.WebForms.PageRequestManager class to validate ASync requests.
  • Sys.WebForms.PageRequestManager You can change the code in the above example and disable the button using simple javascript, for example

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

0
source

Source: https://habr.com/ru/post/1400554/


All Articles