<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
精彩评论