With this code, i try to Close a Window (the way i\'m doing it works) but i have also an Onclick event which is ignored!
I just came across the same issue, and I think we're getting confused between server side enable="false"
and client-side "disable".
The serverside property to enable a control using control.Enabled = "false";
is not the same as applying an Attribute
, like control.Attribute.Add("disabled","disabled");
If you apply the Enabled = false;
from the server side, you're actually turning off the control entirely, even if it's shown on the screen! Go on, try and right click the control and select Inspector
or FireFly
to see it. Nothing shows up. Nothing happens, because the control does not "exist".
Yet if you apply the Attribute
property the control is visible to the server and the client, and you're able to inspect it.
What I did is set up the default environment on the ASP.net side by saying the control (asp:Button
in my case), has Enabled="true"
(or not saying anything, as that's the default anyway).
On the server side, upon PageLoad()
, I make my button Visible (in my case I also had it defaulted to visible="false"
), and add the appropriate Attribute
values.
btnSEND.Visible = true;
btnSEND.Attributes.Add("disabled", "disabled");
That way the button is not enabled, but it's not entirely "invisible" to the client, and by using JavaScript in another area of my program, I control when to enable it or not.
This method also avoids having to use the UseSubmitBehavior="false"
.