Payal Mallik
Payal Mallik

Reputation: 51

ASP.net hiding a div

show a div having the labels for last date if in the database last date is not null else hide the div. I need to hide this div

<div class="form-group" >
    <label class="control-label col-md-3">End Date:</label>

    <div class="col-md-4">
        <asp:HiddenField ID="HiddenField4" runat="server" />
        <asp:Label ID="edate" runat="server" class="form-control">
        </asp:Label>
    </div>

</div>

Upvotes: 0

Views: 109

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460340

Either use a Panel(rendered as div) or make it runat="server", then you can use the Visible property. If a control is Visible=false it won't be rendered at all at client-side:

<div class="form-group" runat="server" ID="FormDiv" >
    <label class="control-label col-md-3">End Date:</label>
    <div class="col-md-4">
        <asp:HiddenField ID="HiddenField4" runat="server" />
        <asp:Label ID="edate" runat="server" class="form-control"></asp:Label>
    </div>
</div>

Note that a server-control also needs an ID.

in codebehind:

FormDiv.Visible = dbLastDate != DateTime.MinValue;

Upvotes: 1

Related Questions