1

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?

2

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.