Html 如何在后面的代码中访问span id
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12290332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access span id in code behind
提问by NealR
I have an asp website with the following control:
我有一个带有以下控件的asp网站:
<span id="expTrainingShow" class="clsLink" style="margin-left: 20px;" onclick="GridChanger();">
+ Show Expired Continuing Education</span>
I want to hide this based on a condition set in the code behind. Can I access a span id like that? (the website is built using visual basic)
我想根据后面代码中设置的条件隐藏它。我可以访问这样的跨度 ID 吗?(该网站是使用visual basic构建的)
回答by Tim Schmelter
You can use a Label
instead of a html-span (which is also rendered as span) or you could add runat="server"
.
您可以使用 aLabel
而不是 html-span(也呈现为 span),或者您可以添加runat="server"
.
<span id="expTrainingShow" runat="server" class="clsLink" style="margin-left: 20px;" onclick="GridChanger();" ></span>
somewhere in codebehind(the span is a HtmlGenericControl
on serverside):
代码隐藏中的某个地方(跨度HtmlGenericControl
在服务器端):
expTrainingShow.InnerHtml = yourText ' set the text '
or
或者
expTrainingShow.Visible = False ' hide it '
Note that Visible=False
on serverside means that the control is not rendered at all on clientside, hence it does not exist in the html and can be accessed only on serverside.
请注意,Visible=False
在服务器端意味着控件根本不会在客户端呈现,因此它不存在于 html 中,只能在服务器端访问。
If you just want to hide it but render it anyway, you should use CSS or expTrainingShow.Style.Add("display","none")
.
如果你只是想隐藏它但无论如何都要渲染它,你应该使用 CSS 或expTrainingShow.Style.Add("display","none")
.