Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > asp labels -- how to avoid a databind() call?

Reply
Thread Tools

asp labels -- how to avoid a databind() call?

 
 
Steve Hershoff
Guest
Posts: n/a
 
      07-30-2007
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?


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      07-30-2007
no, as its a databinding expression.

-- bruce (sqlwork.com)

Steve Hershoff wrote:
> 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?
>
>

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      07-30-2007
Yes if you replace

<%# GetName() %>

with

<%= GetName() %>

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


"Steve Hershoff" <> wrote in message
news:%...
> 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?
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
"pointlabel"-like function for Python: distribute text labels on a2-d scatter plot to avoid overlapping labels C Barrington-Leigh Python 1 09-12-2010 09:58 PM
Avoid having a SQL express for web parts and avoid personalization Roger23 ASP .Net 2 10-12-2006 10:54 PM
Working with multiple versions (labels) with ASP.Net David Gauerke ASP .Net 0 04-15-2004 07:25 PM
Avoid wasting time or how to avoid initialization Alexander Malkis C++ 8 04-13-2004 11:23 PM



Advertisments