简体   繁体   English

如何找到放置在面板中的div控件?

[英]How do I find a div control I placed inside a panel?

I am using a panel there is a div inside this panel . 我正在使用面板,该面板内部有一个div。 I need to set the height and width , css style for this div . 我需要为此div设置高度和宽度,css样式。 But i am not able to find this div id in the c# code . 但是我无法在C#代码中找到此div ID。 How can i get this div id in c# , and add style to this div . 如何在c#中获取此div ID,并向该div添加样式。 Any answer would be appreciated 任何答案将不胜感激

Add runat="server" attribute into div along with its ID. runat="server"属性及其ID添加到div中。

You can set CssClass in that div ID in following way" 您可以按照以下方式在该div ID中设置CssClass

DivID.CssClass = "className";

使该DIV runat="server"并为其提供ID ,然后使用它。

Div1.Style.Add("color","red"); // or any other style attribute in place of color

如果您的div确实具有runat="server"则可以获取对面板的引用,然后使用:

 var div = panel.FindControl("divId");

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

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