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

Discussion in 'ASP .Net' started by Steve Hershoff, Jul 30, 2007.

  1. 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?
     
    Steve Hershoff, Jul 30, 2007
    #1
    1. Advertising

  2. Steve Hershoff

    bruce barker Guest

    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?
    >
    >
     
    bruce barker, Jul 30, 2007
    #2
    1. Advertising

  3. 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?
    >
    >
     
    Eliyahu Goldin, Jul 30, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexander Malkis
    Replies:
    8
    Views:
    551
    Alexander Malkis
    Apr 14, 2004
  2. Roger23
    Replies:
    2
    Views:
    1,039
    Roger23
    Oct 12, 2006
  3. C Barrington-Leigh
    Replies:
    1
    Views:
    674
    C Barrington-Leigh
    Sep 12, 2010
  4. Michael
    Replies:
    0
    Views:
    249
    Michael
    Dec 29, 2003
  5. karlid

    one sql call - multiple labels populated?

    karlid, Sep 24, 2003, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    202
    karlid
    Sep 24, 2003
Loading...

Share This Page