开发者

How do I retain my private level variable in my ASP.NET control after an async postback?

开发者 https://www.devze.com 2023-04-09 05:07 出处:网络
I am using C# and .NET 4.0. I have an ascx control which contains two drop down lists. ddList1 is parent to ddList2 (think Car Make - Car Model). I have a constructor that populates a private variabl

I am using C# and .NET 4.0.

I have an ascx control which contains two drop down lists. ddList1 is parent to ddList2 (think Car Make - Car Model). I have a constructor that populates a private variable in this control with a reference back to the original invoking object. When I do an async postback on the control (caused by changing ddList1), the private variable which was p开发者_如何学运维opulated originally by the constructor is now null.

How do I retain the reference to the original calling object?

Thanks!


Store the value of the variable in your ViewState, and retrieve it during the postback. The Web is stateless: you have to work around that fact, even in WebForms.


Use any of the state management techniques...like sessions or hiddenfields for storing the reference between postbacks

0

精彩评论

暂无评论...
验证码 换一张
取 消