Question

I have two web parts that communicate. The provider can not give a value(an RID) to the consumer until at least the provider's Page_Load event. So the consumer can not know the RID it needs until after Page_Load. So, I hooked into Page_LoadComplete. Now there is a problem. The consumer creates dynamic controls based on this RID.

Now. These dynamic created controls are created after Page_Load. So, their viewstate is not restored(dynamic controls created inside Page_Load do have their values restored though).

So, basically what I need is a way to either restore viewstate to a control manually, or to get the control's value from a POST variable or the equivalent in C#..

Also, if I could get the value of a control at Page_Init, that would work too.

Was it helpful?

Solution

All information returned from a post in in the Request.Form key/values pairs. If you check there and search for the control id in the keys, you can get the value without looking through the view state.

You'll probably have to look through each key and search for the which key contains the control name, because the key will be the Client ID and not the ID you specified.

OTHER TIPS

If the controls are dynamic, they won't be in ViewState until a postback occurs. So ViewState isn't usable on initial load, unless you add them to ViewState yourself.

ViewState.Add("myRID", RID)

Or you can save it in SessionState, and not overload ViewState since ViewState tends to get way too big anyway. I would go with SessionState.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top