I want to call javascript function on label onload, reason I am using an enitity Datasource and assignng a value to this label, but I want to hide it if the value is empty.
Th开发者_如何学Goanx
There are 3 different solutions I can think of off the top of my head:
1) Bind an expression to the visible property of the label that returns true if the value is empty and false if it does not (this will hide it server-side)
<asp:Label id="yourLabel" runat="server" Text='<%# Eval("aField") %>'
Visible='<%# IF(String.IsNullOrEmpty(Eval("aField",True,False))) %>' />
2) If you have jQuery then you can do the following in your script tags:
$(document).ready( function () { $find('label id').hide(); });
3) If you don't have jQuery then you could do some javascript like:
body.onload=function(){
document.getElementById('<%=yourLabel.ClientID%>').style.display = "none";
}
Warning: both pieces of javascript were freeform entry, so they may require some tweaking or spell correction to actually work
<asp:Label ID="Label2"
runat="server"
Text="Name:"
Font-Bold="true" Visible='<%# (!String.IsNullOrEmpty(Server.HtmlDecode((string)Eval("Value")))) %>'>
</asp:Label>
精彩评论