It is common behavior of ASP.NET that if a control is set to
Visible = "false"
display = none
in styles attribute.
Say you have a textbox which you want to make invisible but want to display when required from the browser.
<asp:textbox id="txt" runat="server" />
In codebehind instead of writing
If you take the 2nd approach, the server will render the control and send to the client and finally will not be displayed because of
var elem = document.getElementById("txt");
Note : It is better to use
txt.ClientID instead of
Another issue of ASP.NET is with setting
Enabled = false
In case of
Readonly = true
, ASP.NET sends the input control to the browser, but any changes made in the control in client side will not reflect in the server.
That means, whenever the control is recreated in the web server during postback, it will not include the Form data posted for the control. Thus the initial value will be restored.
Therefore, to overcome the issue again, you should put
This will work the same way but the value changes in the client side will reflect to the server side controls.
Hope you will like this.