How to access span id in code behind

点点圈 提交于 2019-12-07 05:04:43

问题


I have an asp website with the following control:

    <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)


回答1:


You can use a Label instead of a html-span (which is also rendered as span) or you could add 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):

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.

If you just want to hide it but render it anyway, you should use CSS or expTrainingShow.Style.Add("display","none").



来源:https://stackoverflow.com/questions/12290332/how-to-access-span-id-in-code-behind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!