views:

46

answers:

2

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?

+1  A: 

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"];
}
Darin Dimitrov
thanks for the suggestin but it doesn't seem to work, its just sending the literal string '<%# Session["mycontrolvalue"] %>' to the control instead of working out what Session["mycontrolvalue"] actually is
William Calleja
A: 

Can you post a code snippet pls?

5arx