text for asp:label from session

Discussion in 'ASP .Net' started by tshad, Feb 3, 2005.

  1. tshad

    tshad Guest

    How do I set up text (or can I) set up a label to automatically pull in text
    from a session variable. Something like:

    <asp:label text="<%# session("ClientName") %>" runat="server"/>

    This doesn't work, but is there a way to have it do this with out having to
    set up code in the Page_Load sub to accomplish this?

    Thanks,

    Tom
    tshad, Feb 3, 2005
    #1
    1. Advertising

  2. tshad

    Karl Seguin Guest

    Tom:
    Create a custom control:

    public class ClientName
    Inherits Label

    public override sub Render(Writer as HtmlTextWriter)
    if not session("ClientName") is nothing then
    Text = cstr(Session("ClientName"))
    else
    Text = "Anonymous"
    end if
    myBase.Render(writer)
    end sub
    end class


    not tested, but something like that ought to work.

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "tshad" <> wrote in message
    news:%...
    > How do I set up text (or can I) set up a label to automatically pull in

    text
    > from a session variable. Something like:
    >
    > <asp:label text="<%# session("ClientName") %>" runat="server"/>
    >
    > This doesn't work, but is there a way to have it do this with out having

    to
    > set up code in the Page_Load sub to accomplish this?
    >
    > Thanks,
    >
    > Tom
    >
    >
    Karl Seguin, Feb 3, 2005
    #2
    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. Shapper
    Replies:
    2
    Views:
    731
    Scott Mitchell [MVP]
    May 7, 2005
  2. Josef K.

    <label><div></div></label> allowed?

    Josef K., May 20, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    13,399
    Josef K.
    May 22, 2005
  3. Praveen
    Replies:
    1
    Views:
    966
    Rob Williscroft
    Nov 5, 2006
  4. CSharpner
    Replies:
    0
    Views:
    1,018
    CSharpner
    Apr 9, 2007
  5. Knut Krueger
    Replies:
    8
    Views:
    265
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page