简体   繁体   English

有效使用ASP.NET向导的准则

[英]Guidelines for using the ASP.NET Wizard efficiently

A web app our group has put together uses the ASP.NET Wizard control. 我们小组共同编写的Web应用程序使用ASP.NET向导控件。 Each step in the wizard contains a corresponding custom UserControl. 向导中的每个步骤都包含一个相应的自定义UserControl。

The trouble is that as you go through the wizard steps, all the UserControls are loaded on each step, rather than just the one used in that step. 问题在于,当您完成向导步骤时, 所有 UserControl都加载在每个步骤上,而不仅仅是在该步骤中使用的那个。 That doesn't seem right to me. 这对我来说似乎不对。

So...is there anybody here that's done a lot of work with the Wizard control and can give some guidelines on how to use it correctly, and keep it from loading way too much junk with each step? 所以...这里有人在使用向导控件方面做过很多工作,并且可以提供一些有关如何正确使用它的指南,并防止每个步骤使它加载过多的垃圾吗?

One thing that could help you a bit is not putting any code in your UserControls's Page_Load function but instead putting that same code in it's Page_PreRender. 可能对您有所帮助的一件事不是在UserControls的Page_Load函数中放入任何代码,而是在Page_PreRender中放入了相同的代码。 That's crucial when using a MultiView and probably applies to the wizard as well. 这在使用MultiView时至关重要,并且可能也适用于向导。

mspmsp has a good recommendation about PreRender, another option that I have noticed used before is to simply move all configuration code inside the control to a ConfigureControl method. mspmsp对PreRender有很好的建议,我之前注意到的另一个选项是将控件内的所有配置代码简单地移到ConfigureControl方法。

Then when switching views, you can call the ConfigureControl() method to explicitly create/load your control. 然后,在切换视图时,可以调用ConfigureControl()方法来显式创建/加载控件。 It has the same purpose, but it helps make the code a bit easier to understand in my opinion. 它具有相同的目的,但是在我看来,这有助于使代码更易于理解。

FYI, (at least part of) the reason it loads all user controls on each step is so that you can access the values entered on other steps. 仅供参考,(至少部分是)在每个步骤上加载所有用户控件的原因是,以便您可以访问在其他步骤上输入的值。 If it didn't load the controls, you couldn't easily make decisions about the current step based on what was entered in a previous step (eg filtering a list based on a selection in a previous step). 如果未加载控件,则无法基于上一步中输入的内容轻松地做出有关当前步骤的决定(例如,根据上一步中的选择过滤列表)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM