Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve Hershoff - 30 Jul 2007 19:26 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.