I have googled this and didn't find what I needed. All of the existing solutions I found say to set "visibility" to false. This will not seem to work for me as my application renders PDF which simply "hides" the DIV and leaves a big white space in it's place.
Instead, I would like to not render the HTML at all. For instance, in PHP, this could be done as simply as:
<?php if ($showDiv == true) { ?>
<div>Lorem ipsum dolor sit amet</div>
<?php } ?>
In ASP.NET MVC, I could simply pass a ViewBag variable and do the same thing.
What is the solution for this in ASP.NET (C#)?
<% if ( showDiv ) { %>
<div></div>
<% } %>
where showDiv would be a protected property in your code behind.
In the aspx file
<div runat="server" id="hideableDiv">Lorem ipsum dolor sit amet</div>
And in the code behind
...
hideableDiv.Visible = false;
...
use a <asp:panel>
control which renders as a HTML <div>
. You can then toggle the visibility. If visible
is set to false, asp.net will not render any content.
<asp:Panel id="MyPanel" runat="server">
...
</asp:Panel>
MyPanel.Visible = false;
The markup
<div runat="server" id="myPdfDiv">Lorem ipsum dolor sit amet</div>
The codebehind
myPdfDiv.Visible = false;
myPdfDiv.InnerHTML = "";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With