Click here to Skip to main content
15,884,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a basic test ASP MVC web project that displays a list of 10 names and allows the user to select/edit any name. The project works fine.
My question relates to the edit view after the uses selects 'edit' for one of the listed names. The edit action code is listed below.

How do I change the text of the save button on the edit view to 'Please wait' while the data is posted back. As you can see from the code there is a 3 sec wait to simulate a delay.


here is the snippet of code from the edit.vbhtml code for the edit view.

<div class="col-md-offset-2 col-md-10">
               <input type="submit" value="Save" class="btn btn-default" />
           </div>


I have tried using onclick but it doesnt fire.

can anybody help please?


Function Edit(ByVal id As Integer) As ActionResult
    Dim student As KeithViewModel = New KeithViewModel With {
            .Id = id,
            .Name = "Name" & id}

    Return View(student)
End Function

' POST:
<HttpPost()>
Function Edit(ByVal rec As KeithViewModel) As ActionResult
    Try
        ' TODO: Add update logic here

        System.Threading.Thread.Sleep(3000)
        Return RedirectToAction("Index")
    Catch
        Return View()
    End Try
End Function


What I have tried:

<button type="submit"

     id="submitButton"

     class="btn btn-primary"

     onclick="return

              DisplayProgressMessage(this, 'Saving...');">

  Save

</button>


JavaScript
<script>

  function DisplayProgressMessage(ctl, msg) {

    $(ctl).prop("disabled", true);

    $(ctl).text(msg);

 
    return true;

  };

</script>
Posted
Comments
j snooze 26-Feb-21 17:11pm    
Why not put the 3 second wait and submit in the javascript, once you post back to the server code you can't mess with the client side until it renders again.
I see the dollars signs so I'm assuming you are using jquery already, it has a submit, so just put an onclick event on your input and make it a type button instead? This is just a suggestion, I do not know your specs or why you would put a 3 second delay on the server side code.
Taggart 28-Feb-21 2:50am    
Thanks for your comment. I was hoping the submit on the input statement would process after any onclick event logic. clearly it doesnt, so I'll try your suggestion.
The 3 sec delay on the server side is to simulate the time for any database updates in the real world, so the change to the button text can be seen for a few seconds.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900