how to implment click-once submit button in asp.ne

2019-06-12 12:34发布

问题:

I need to implement a click-once button for my asp.net mvc 2 application. I have just a very simple submit form, and when the user clicks on the submit button, I need to change its image to a "please wait..." type of graphics and disables the click event for further submits until the server comes back.

Is there an example or code snippet for this? I used to be able to do it in the asp.net webforms, but that technique does not apply here.

thanks!

回答1:

To disable the submit button when you submit the form you can use the onSubmit function for the form and call a javascript function that will disable the button.

For example:

<% using (Html.BeginForm("Create", "Organisation", FormMethod.Post, new { autocomplete = "off", onsubmit = "disableSubmitButton()" }))
   { %>
       //Your code

      <input id="buttonName" type="submit" value="Create"/>
  <% } %>

and then in your javascript section:

function disableSubmitButton() {

    document.getElementById("buttonName").disabled = true;

};

Hope this helps.



回答2:

Here is example of how create ajax login using asp.net mvc and jQuery: How to implement a Client-side Ajax Login on Asp.Net MVC (A link to the solution for Asp.Net Webforms is in here)