Reputation: 13
I’m new to C# and JavaScript.
I created a button in a aspx page that connects to an aspx.cs page. That page does a "write to file" when the button is pushed. (written in c#) I would like for the button to become disabled after the file has been written to.
The problem I'm running into is the automatic postback is resetting my button back to an active status. From what I’ve read, the solution is to disable the button with JavaScript. I can do that, but when I do my c# code on the .cs isn’t running. I believe it’s because the JavaScript is running before the c#. Is there a trick to getting the c# code on the aspx.cs page and then disable the button?
Upvotes: 1
Views: 170
Reputation: 383
Including this in your code-behind (.cs file) should be enough:
protected void Button1_Click(object sender, EventArgs e)
{
// Write to file...
Button1.Enabled = false;
}
This should persist even across postbacks, although form elements will still reset on full page loads.
Upvotes: 1