简体   繁体   中英

Displaying a control in JavaScript when it is programmatically hidden in ASP.NET Webforms

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

在此处输入图像描述

在此处输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM