Reputation: 31
I have a webforms button having id "btnUpdate", I have make this button visible False in c# by using "btnUpdate.Visible = false". After it, I want to show this button using javascript on the basis of some condition by writing "document.getElementById("btnUpdate").style.display = 'block'". But its displayed error that control having id "btnUpdate" does not exist. It is requested to assist me regarding this issue. Thanks
Upvotes: 0
Views: 127
Reputation: 22446
If you set Visible = false
, ASP.NET WebForms does not include the button on the rendered HTML that is sent to the client. So you cannot access it in JavaScript.
If you instead just hide it, you will find it in the HTML:
btnUpdate.Attributes["hidden"] = "true";
Instead of changing display in JavaScript, you remove the hidden
attribute in order to show the button. If you want to stick with using the display property, you can change the code in above sample accordingly and use the Styles
property of the control.
Upvotes: 2