Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This just doesn't make sense, casting a string value to a Control.</p> <p>As far as I can see, you are not inserting a Control into the Sessiosn, not even the Control.ToString() value, which also wouldn't be working.</p> <p>Before continuing, it might be usefull to check which type is retrieved from the Session without casting anything (remark: this is only possible with .NET 3.5 or higher):</p> <pre><code>var sessionValue = Session["ctrl"]; </code></pre> <p>When doing so, you will find out the value is of type object, containing the value:</p> <pre><code>"&lt;div&gt;\r\n\r\n&lt;/div&gt;" </code></pre> <p>The above output is not a Control, but a string/html value.</p> <p>There are two solution paths which u can follow:</p> <ul> <li>Change the "SET" call on the Session</li> <li>Change the "GET" call on the Session</li> </ul> <p>In the second example, you keep to the fact that you are inserting a string and therefor you would like to read out that string value:</p> <pre><code>string sessionValueAsString = string.Empty; Object sessionValue = Session["ctrl"]; if (sessionValue != null) sessionValueAsString = sessionValue.ToString(); </code></pre> <p>The above example could suit ur needs, never the less I'm guessing you are in the need to save an object of type "Control" in the session. This can be achieved like so:</p> <pre><code>MyControl myControl = new MyControl {Title = "My custom control"}; Session["myControl"] = myControl; // Read the Session value cross Postback MyControl mySessionControl = (MyControl)Session["myControl"]; </code></pre> <p>Apart from the above example, I'm not 100% sure what you are trying to do. My guess is you made a mistake inserting the wrong value in the Session.</p> <p>One remark: I'm not a fan of storing the WebControls in the session, it would be cleaner to store your data objects in the Session (e.g. store a Customer class instead of the CustomerUserControl, this way you can read out the Session and populate the required controls using the data found in the Session). </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload