User control viewstate
-
I need to have a value set in one user control and then accessible to another user control on the same page. My first thought was to use ViewState but this obviously won't work. Ended up using cache instead but is there a better method to accomplish this? Using server controls instead of user controls is out of the question for this client.
-
I need to have a value set in one user control and then accessible to another user control on the same page. My first thought was to use ViewState but this obviously won't work. Ended up using cache instead but is there a better method to accomplish this? Using server controls instead of user controls is out of the question for this client.
Mark Nischalke wrote: Using server controls instead of user controls is out of the question I'm confused. User Controls are processed on the server. Viewstate is also a server side technology. It has no meaning on the client side and is really just along for the ride (the server sends it to the client, the client doesn't use it but it is sent back to the server on the next page request) Mark Nischalke wrote: Ended up using cache What do you mean by this?
Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
-
Mark Nischalke wrote: Using server controls instead of user controls is out of the question I'm confused. User Controls are processed on the server. Viewstate is also a server side technology. It has no meaning on the client side and is really just along for the ride (the server sends it to the client, the client doesn't use it but it is sent back to the server on the next page request) Mark Nischalke wrote: Ended up using cache What do you mean by this?
Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
In ascx1 I set ViewState["SomeValue"] = 1 ViewState["SomeValue"] is set properly and is usable elsewhere during the rendering of ascx1 In ascx2 I try to read ViewState["SomeValue"] but it is null I ended up using Cache.Insert on ascx1 with a very short time ( 5 sec ) and Cache.Remove on ascx2 when I'm done with it. A better implementation anyway since I don't need this value on the postback, only during processing.
-
In ascx1 I set ViewState["SomeValue"] = 1 ViewState["SomeValue"] is set properly and is usable elsewhere during the rendering of ascx1 In ascx2 I try to read ViewState["SomeValue"] but it is null I ended up using Cache.Insert on ascx1 with a very short time ( 5 sec ) and Cache.Remove on ascx2 when I'm done with it. A better implementation anyway since I don't need this value on the postback, only during processing.
There are a number of ways: You could stick it in the Session object. (Remembering to clean it out on the page_unload) Store it in the page class (although that might get a bit complex as you'd have to implement a storage mechanism on all pages that that these two controls sit on). I'm not sure if you can do this with user controls (or if it is feasible in your case), but if you can have a user control that contains these two controls, so a Master.ascx contains ascx1 and ascx2. The code for ascx1 seeks out ascx2 on the page controls and directly plants the value in ascx2.
Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
-
There are a number of ways: You could stick it in the Session object. (Remembering to clean it out on the page_unload) Store it in the page class (although that might get a bit complex as you'd have to implement a storage mechanism on all pages that that these two controls sit on). I'm not sure if you can do this with user controls (or if it is feasible in your case), but if you can have a user control that contains these two controls, so a Master.ascx contains ascx1 and ascx2. The code for ascx1 seeks out ascx2 on the page controls and directly plants the value in ascx2.
Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
Colin Angus Mackay wrote: You could stick it in the Session object. I used Cache with sessionID as the key, but this may be cleaner.
-
I need to have a value set in one user control and then accessible to another user control on the same page. My first thought was to use ViewState but this obviously won't work. Ended up using cache instead but is there a better method to accomplish this? Using server controls instead of user controls is out of the question for this client.
What would happen if the second user control was on a page but the first one was not? You'd have a problem. I'd suggest designing the controls such that they don't depend on the existence of other specific controls on the page. Now in your app, that may not ever happen, but you never know... As a result, you'd need the second control to get the value differently. Some ideas have already been mentioned (e.g. use Session state). Or, the page the control is on could set the value too. Michael Hodnick www.kindohm.com blogs.kindohm.com