简体   繁体   English

在asp.net后面的代码中更改CSS

[英]Changing the CSS in code behind asp.net

in my aspx page I have this div.. 在我的aspx页面中我有这个div ..

<div id="downloadableProducts" runat="server"><a href="#">Downloadedable Products</a></div>

I am trying to change the css in the code behind like this.. 我试图改变后面的代码中的CSS像这样..

downloadableProducts.Style("display") = "none";

but this does not work, I get an error and red underline under downloadableProducts in the code behind and it says 'The name 'downloadableProducts' does not exist in the current context ' 但这不起作用,我在后面的代码中的downloadableProducts下得到一个错误和红色下划线,并且它说“当前上下文中不存在名称'downloadableProducts'”

What am I doing wrong? 我究竟做错了什么?

You need to add runat="server" to the div and access it as a HtmlControl in your codebehind. 您需要将runat="server"添加到div并在代码隐藏中将其作为HtmlControl访问。 For example: 例如:

HtmlControl div1 = (HtmlControl)Page.FindControl("downloadableProducts");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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