Reputation: 4175
I have an ASP control custom built and I need to pass a value taken from a session variable to it like so:
<custom:control id='mycontrol' value="+Session['myControlValue']+">
...
</custom:control>
the above code obviously doesn't work, I need a way to insert the Session value in the control in this way somehow, can anyone help?
Upvotes: 0
Views: 1067
Reputation: 1
Switch the quotes, like so:
<custom:control id="mycontrol"
runat="server"
value='<%# Session["myControlValue"] %>' />
Upvotes: 0
Reputation: 1039130
If it is a data bound control you may try this:
<custom:control id="mycontrol"
runat="server"
value='<%# Session["myControlValue"] %>'>
</custom:control>
Personally I would prefer setting this value from the code behind. It seems a little strange to me that a view (aspx) page manipulates the session:
protected void Page_Load(object sender, EventArgs e)
{
mycontrol.Value = Session["myControlValue"];
}
Upvotes: 1