Hi everybody,
I have a question about asp.net's labels and the DataBind method. I have a
method in a code-behind page (this is VisualStudio 2003 btw) that
(simplified) looks like this:
public string GetName()
{
string sName = "";
if(Session["ds"] != null)
sName = Session("fname").ToString() + " " +
Session("lname").ToString();
return sName;
}
My label code says this:
<asp:Label CssClass="Normal2" Runat="server" ID="Label124">
<%# GetName() %>
</asp:Label>
The thing is, I can't execute GetName() unless I call Label124.DataBind() in
my code-behind. Is there a way to do it without the DataBind() call?
bruce barker - 30 Jul 2007 20:54 GMT
no, as its a databinding expression.
-- bruce (sqlwork.com)
> Hi everybody,
>
[quoted text clipped - 19 lines]
> The thing is, I can't execute GetName() unless I call Label124.DataBind() in
> my code-behind. Is there a way to do it without the DataBind() call?
Eliyahu Goldin - 30 Jul 2007 23:01 GMT
Yes if you replace
<%# GetName() %>
with
<%= GetName() %>

Signature
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
> Hi everybody,
>
[quoted text clipped - 19 lines]
> The thing is, I can't execute GetName() unless I call Label124.DataBind() in
> my code-behind. Is there a way to do it without the DataBind() call?