且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

动态改变在ASP.Net用户控件

更新时间:2023-12-06 10:19:28

这是典型的撕裂你的头发出的问题与ASP.Net web表单。您有几种选择:

This is the classic tear-your-hair-out problem with ASP.Net webforms. You have several options:

1)这是一个黑客位,因为它进入预定页面生命周期之外的位,但在我的经验,这是处理问题的最直接的方式。当页面职位从下拉评选活动,只需查询请求[MyDropDownID] 的下拉控件期间选定值初始化回() - 不要等待 OnMyDropDownChanged()事件来设置页

1) This is a bit of a hack, since it goes outside the intended page lifecycle a bit, but in my experience it's the most direct way of dealing with the problem. When the page posts back from the drop down selection event, simply poll Request["MyDropDownID"] for the selected value of the drop down control during Init() - don't wait for the OnMyDropDownChanged() event to set up your page.

2)实现自己的ViewState处理您的用户控件。这需要挖入的ViewState文档并覆盖了一些方法

2) Implement your own ViewState handling for your user controls. This requires digging into the ViewState documentation and overriding a number of methods.

3)乔尔的解决方案。他打我,​​但我试图让第一篇文章:P

3) Joel's solution. He beat me to it but I was trying to get first post :p

其他选项包括使用JavaScript和刊登这些资料价值,但那些带来麻烦。

Other options involve posting values using javascript and such, but those get really messy.