How to access span id in code

I have an asp site 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 the condition set in the code. Can I access the span id? (website built using visual basic)

+4
source share
1 answer

You can use Label instead of html-span (which also appears as span), or you can add runat="server" .

 <span id="expTrainingShow" runat="server" class="clsLink" style="margin-left: 20px;" onclick="GridChanger();" ></span> 

somewhere in codebehind (span - HtmlGenericControl on the server):

 expTrainingShow.InnerHtml = yourText ' set the text ' 

or

 expTrainingShow.Visible = False ' hide it ' 

Please note that Visible=False on the server means that the control is not displayed at all on clientide, therefore it does not exist in html and can only be accessed on servers.

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

+14
source

Source: https://habr.com/ru/post/1432585/


All Articles