How to run client and server code for the same button?

In the Asp.NET aspx page there is a button for saving data, when the user clicks on this button, I want: 1. Immediately disable this button. 2. Then call the code behind the Save () function to save the data back to DB 3. Then turn on this button again.

What I did as shown below:

  • JS function in apsx:

    function DisableSave () {saveButton = document.getElementById ('<% = btnSave.ClientID%>'); saveButton.disabled = TRUE; return false; }

  • Script button:

    <--- asp: Button ID = "btnSave" OnCommand = "Button_Command" CommandName = "Save" runat = "server" Text = "Save" OnClientClick = "javascript: DisableSave ();" / ">

  • In the code behind the Save () function (supposedly called by CommandName), set the Save button to go back.

But when I run the code, disable only the save button, the code after the call did not happen.

How to fix it?

+5
source share
2 answers

Apparently, some browsers (IE) will not handle the button submit action if it is disabled. I tried this in Firefox and it made a postback, but no luck with IE. One workaround, although not providing user feedback, is to do this OnClientClick="this.onclick= function() { return false; }". This will at least prevent more e-mail messages from appearing.

EDIT: onclick needs to be a function, not a string.

+3
source

, JavaScript onclick .

this CodeProject.

+2

All Articles