如何访问用户控件的td元素,并从aspx页面将其设置为可见的true或false [英] how to access td element of user control and set it to visible true or false from aspx page
本文介绍了如何访问用户控件的td元素,并从aspx页面将其设置为可见的true或false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个aspx页面,这个页面继承了ascx页面。我想从.aspx页面隐藏ascx页面的td元素。我怎么能这样做,请尽快回复
谢谢
快乐编码
i have a aspx page and this page inherits the ascx page. i want to hide the td element of ascx page from .aspx page. how can i do that please reply as soon as possible
thanks
happy coding
推荐答案
要访问asp.net代码中的元素,必须有runat = server
为该元素设置。
在您的情况下,我建议您在一个范围内包含要更改其显示属性的HTML,并将runat服务器标记添加到它。所以你的HTML将是这样的:
To access an element in your asp.net code, you must haverunat="server"
set for that element.
In your case, I would suggest you wrap the HTML whose display property you want to change in a span and add runat server tag to it. So your HTML will be something like:
<td>
<span id="spnUsercontrolHtml" runat="server">
<!--your user control html... or whatever html/text here -->
</span>
</td>
你可以在服务器端访问spnUsercontrolHtml,你可以将它的可见性或样式设置为false / none。
You can access spnUsercontrolHtml at server side and you can set it''s visibility or style to false/none.
spnUsercontrolHtml.Visible = false;
spnUsercontrolHtml.Style.Add(HtmlTextWriterStyle.Display, "none");
希望这会有所帮助!
Hope this helps!
试试这个,
http://www.hrushiphapale.org/2012/08/ enabledisable-control-and-its-child.html [ ^ ]
希望它一定能帮到你...
try this,
http://www.hrushiphapale.org/2012/08/enabledisable-control-and-its-child.html[^]
hopes it will surely help you...
请参阅下面的语法如果控件是文本框
TextBox myTextBox = userControl.FindControl(YourTextBox)作为TextBox;
myTextBox.Visible = false;
Please see below syntax If control is textbox
TextBox myTextBox = userControl.FindControl("YourTextBox") as TextBox;
myTextBox.Visible=false;
这篇关于如何访问用户控件的td元素,并从aspx页面将其设置为可见的true或false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文