I’m trying to create a c# function that would hide all child elements that had no innerhtml for the html control that was passed. Could someone point me in the right direction? Not real sure where to start on this one.
I’m using asp.net 4. Here’s an example of my html structure..
<div id="officeInfo" runat="server">
<h2><%= mlaLocationDTO.Name %></h2>
<p><%= mlaLocationDTO.Address.Street1 %></p>
<p><%= mlaLocationDTO.Address.Street2 %></p>
<p>Tel:<%= mlaLocationDTO.Phone %></p>
<p>Fax:<%= mlaLocationDTO.Fax %></p>
<p>Email:<%= mlaLocationDTO.Email %></p>
<a href="#">Get Directions</a>
<a href="#">Submit Your Resume</a>
</div>
And my psuedo function…
protected void HideHtmlElementsWhenEmpty(Control element)
{
foreach (Control c in element.Controls) maybe there's a better way than to use a loop
{
if(c.innerHtml != null) //not sure what to do here
{
c.Visible = false;
}
}
}
Thanks!
Output the HTML tags conditionally:
Oh, and don’t forget to properly encode your database output: Street1 might contain
<or other HTML-unsuitable characters, and we don’t want to risk any script injection…