Monday, March 26, 2012

text for asp:label from session

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,

TomTom:
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" <tscheiderich@.ftsolutions.com> wrote in message
news:%23qeKbChCFHA.464@.TK2MSFTNGP15.phx.gbl...
> 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

0 comments:

Post a Comment