pahluwalia

pahluwalia

  • NA
  • 11
  • 0

Disabling button fires Postback on click ASP.NET 2.0

Feb 1 2007 3:37 PM
This is a very weird problem that I am facing. I have a button with required field validator for a textbox. And all I do in Page_Load is to disable that button and enable it when something in textbox is entered. The problem is everytime I click the button, even if the textbox is empty, it fires a postback.

If I dont disable the button in page load, it works fine.

Any help will be greatly appreciated.

Here is Page_Load:

btn.Enabled = false;

text1.Attributes.Add("onchange", "document.form1.btn.disabled=false;");

And this is the aspx page:

<form id="form1" runat="server">

<asp:ValidationSummary ID="vsImportExclusions" runat="server" ValidationGroup="import" />

<asp:TextBox ID="text1" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator ID="rtext1" ControlToValidate="text1" runat="server" ErrorMessage="ERROR" ValidationGroup="import" Display="None"></asp:RequiredFieldValidator>

<asp:Button ID="btn" Text="OK" runat="server" ValidationGroup="import" />

</form>


Answers (1)