在ASP动态加载的用户控件最佳实践 [英] Best Practice for Dynamically loading User Controls in ASP
问题描述
我有了52自定义控件在preINIT程序通过加载所有的ViewState保持一个ASP网页
这是取决于哪个报告,到自定义控件的5可见,但不是所有的报表生成器页面。
例如,
- 客户报告不需要员工的问题。
- 和雇员报告不需要客户端的问题。
- 但都需要的日期范围的问题。
(而这一切完美的作品)
但是...
我想不是的只加载是适合于报告中指出,用户正在运行的控制。 (这声音对我来说)就像我需要存储在其控制在ViewState中加载信息。
问题是...视图状态不是在preINIT日常使用,所以我不能用它来确定控制加载。
我的选择是,然后存储在其控制加载中的信息:
- SessionState会。
- 数据库
- URL参数。
- 别的东西我都没有想到的。
每个中载有自己的问题做什么,我需要。
什么(在您看来)是我们的最佳做法。
我的code(剪断)
私人小组WebForm2_ preINIT(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手我。preINIT ReportOptions.Controls.Add(的UserControl1)
ReportOptions.Controls.Add(UserControl2)
ReportOptions.Controls.Add(UserControl3)
等等...结束小组
我的HTML(SNIP)
< DIV ID =ReportOptions级=ReportOptions=服务器/>
ViewState是不是因为你必须以在立柱正确读取视图状态恢复重建你的页面,正是因为它是(控制和全部)的选项。
会话sux的。 (在asp.net提供商单线程)
是数据库的方式来重,矫枉过正。
URL方法是无状态的,可能你最好的选择。
I have an ASP webpage that has 52 custom control all maintaining ViewState by loading in the PreInit routine
It is a report generator page that depending on which report, up to 5 of the custom controls are visible but not all of them.
For instance,
- The Client report does not need the Employee questions.
- And the Employee report does not need the Client questions.
- But both need the Date Range questions.
(and all this works perfectly)
BUT...
I would like to instead LOAD ONLY the controls that are appropriate for the report that the user is running. (Which sound to me) like I need to store information on WHICH controls to load in the ViewState.
Problem is... viewstate is not available in the PreInit routine, so I cannot use it to determine which controls to load.
My options are then to store the information on WHICH controls to load in:
- SessionState.
- Database
- URL argument.
- Something else I haven't thought of.
Each of which carries its own problems for doing what I need.
What (in your opinion) is the best practice for this.
My code (snip)
Private Sub WebForm2_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
ReportOptions.Controls.Add(UserControl1)
ReportOptions.Controls.Add(UserControl2)
ReportOptions.Controls.Add(UserControl3)
Etc...
End Sub
My HTML (snip)
<div id="ReportOptions" class="ReportOptions" runat="server"/>
Viewstate is not an option because you must reconstruct your page exactly as it was (controls and all) in order to read the view state correctly on a post back.
Session sux. (single threaded in asp.net provider)
Database is way to heavy and an overkill.
URL method is stateless and probably your best bet.
这篇关于在ASP动态加载的用户控件最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!