[英]Hiding a button inside a div from code
I have a aspx page and i want to hide the button from cs file based on my some condition 我有一个aspx页面,我想根据我的某些条件从cs文件中隐藏按钮
My .aspx looks like : 我的.aspx看起来像:
<asp: Content Id="contentid" >
<% if (!IsRedeemCardFlowOptin)
{ %>
<ul id="ulid" class="abc">
</ul>
<div class="bcd" id ="div1">
<div id="div2"></div>
<div id="div3"></div>
<div id="div4" runat="server">
<h4><%= m_AutoRenewInfo.NewPageContent.ArCsidOffHeader%></h4>
<button class="abc bcd cde" title="Button" id="buttondiv"><span>Button</span></button> //Want to hide this button
</div>
</div>
<% } %>
</asp:Content>
Now in the cs file i want to hide the button with id "buttondiv", how can i do that 现在在CS文件中,我想隐藏ID为“ buttondiv”的按钮,我该怎么做
In my cs file, i try this 2 things but it doesnt work 在我的cs文件中,我尝试了这2件事,但是它不起作用
Control myDiv = (Control)FindControl("buttondiv");
myDiv.Visible = false;
Or 要么
foreach (Control c in contentid.Controls)
{
if (c.ID == "buttondiv")
{
c.Visible = false;
}
}
Can anyone let me know 谁能告诉我
In order to be used as a server-side control, the button would need to be a server-side control. 为了用作服务器端控件,该按钮将需要是服务器端控件。 Add
runat="server"
: 添加
runat="server"
:
<button class="abc bcd cde" title="Button" id="buttondiv" runat="server">
Then (unless you've broken the designer somehow, it's been a while since I've used Web Forms) you should have an HtmlControl
object in your class that you can set without the need to "find" the control: 然后(除非您以某种方式破坏了设计器,自从我使用Web Forms已经有一段时间了),您应该在您的类中具有一个
HtmlControl
对象,您可以对其进行设置,而无需“查找”控件:
this.buttondiv.Visible = false;
Kindly keep this in css file. 请将此保存在css文件中。
#buttondiv{
display:none;
}
Or apply style inline like below: 或如下应用内联样式:
<button class="abc bcd cde" title="Button" id="buttondiv" style="display:none"><span>Button</span></button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.