开发者

Add Session Value to HiddenField placed in web control

开发者 https://www.devze.com 2023-01-07 22:34 出处:网络
<asp:HiddenField ID=\"mypostID\" runat=\"server\" Value=\"\"/> I wanted to ask if I could do something like:
<asp:HiddenField ID="mypostID" runat="server" Value=""/>

I wanted to ask if I could do something like:

<asp:HiddenField ID="mypostID" runat="server" Value="<% Response.Write(Session["ïd"])%>"/>

I cannot access the session from the user control code behind but if I put a Respose.Write on the page itself it shows the sessi开发者_JAVA技巧on value.

Thanks


Use HTTPContext.CurrentContext.Current.HTTPSessionState to access session states from the code behind of the control.


You need to specify the Fully Qualified Namespace for the HTTP Session in this case, because you're in a user control.

When you do Session["foo"] in a user control, it will access the UserControl.Session property (see here), not the HttpContext.Session.

So do it like this:

HttpContext.Current.Session("foo")

See more details on HttpContext.Current.Session here

0

精彩评论

暂无评论...
验证码 换一张
取 消