如何在c#中动态创建向导控件?

时间:2021-04-09 00:03:26

I'm creating a web form that gathers customer information and inserts it into a database. Customers can have 3 kinds of accounts: Combined accounts (bill and ship to this location), Billing Accounts (only bill to this location), and shipping accounts (only ship to this location.

我正在创建一个web表单,它收集客户信息并将其插入到数据库中。客户可以有3种账户:合并账户(账单和船到这个位置),账单账户(只有到这个位置的账单),以及发货账户(只有到这个位置的船)。

The information gathered is broken down into 5 categorizes: General (store name, address, ext..) employees, owners (of that particular location), trade references, and banking.

收集的信息分为5个类别:一般(商店名称、地址、ext..)雇员、所有者(特定位置的所有者)、交易引用和银行。

I currently have a wizard with 5 steps (one for each category), but I won't need all of them depending on the account type. Shipping addresses, for instance, requires General and employee information, optionally needs owner information, and should never have Trade Reference nor Banking information. Also, the user will need to completely fill out the general information category before the account type can be determined.

我现在有一个有5个步骤的向导(每个类别一个),但我不需要它们全部依赖于account类型。例如,配送地址需要通用和员工信息,或者需要所有者信息,并且不应该有交易引用和银行信息。此外,用户还需要在确定帐户类型之前完全填写一般信息类别。

There doesn't seem to be a way to disable an entire wizard step (by which I mean a link to it doesn't show up on the sidebar and it is impossible to navigate to), so I'd like to dynamically create the wizard so that I only get the steps I need. The problem is that the wizard is currently 700+ lines of code on the .aspx page, and dynamically creating it will probably take double that (if I'm lucky).

似乎没有一种禁用整个向导步骤”(我是指链接它不出现在侧边栏和导航到是不可能的),所以我想动态创建向导,我只得到我所需要的步骤。问题是,该向导目前在.aspx页面上有700多行代码,并且动态创建它可能需要加倍(如果我幸运的话)。

Is there some way I can Statically create each step, then dynamically decide which steps to use in my wizard or is purely dynamic my only option?

是否有某种方法可以静态地创建每一个步骤,然后动态地决定在我的向导中使用哪些步骤,或者纯粹是动态的?

Or (and this is the most likely case) is there a much simpler solution that will get me the results I'm looking for?

或者(这是最有可能的情况)有一个简单得多的解决方案能让我得到我想要的结果吗?

1 个解决方案

#1


0  

Given the highly customizable needs of wizards, a lot of them have gone by the wayside in favor of creating all of the code by hand. It is safe to assume that the wizard you're talking about here is the ASP.Net WebForm Wizard object? I believe that server control has not been updated in a while.

考虑到向导的高度可定制的需求,他们中的很多人已经放弃了手工创建所有代码的方式。假设您正在讨论的向导是ASP,这是安全的。净WebForm向导对象?我相信服务器控制在一段时间内没有更新。

One thing you could look into doing is building all of the UI elements client side, and then have AJAX / WebAPI endpoints do the data processing. By taking this route, you can easily show/hide/customize the various tabs/steps based on the type of account type being processed (you can get that from the URL, or hidden form field, or something else). You can do a google search for "jQuery wizard builder" or something similar to find libraries out there.

您可以研究的一件事是构建所有UI元素客户端,然后使用AJAX / WebAPI端点进行数据处理。通过使用此路由,您可以很容易地根据正在处理的帐户类型的类型来显示/隐藏/自定义各种选项卡/步骤(您可以从URL,或隐藏的表单字段,或其他东西中获得这些)。您可以使用谷歌搜索“jQuery向导生成器”或类似的查找库。

Decoupling the presentation from the data processing in this regard will give you more flexibility. It still may take a little more than the 700 lines of code, but you will have greater control over what, how, and when the the data is processed for your end user. You can setup the wizard to post to your service after each step, or wait until all data has been collected before making the submission.

将表示与此方面的数据处理分离开来,将给您带来更大的灵活性。它仍然可能需要比700行代码多一点,但是您将会更大的控制什么,如何,以及何时为您的最终用户处理数据。您可以设置向导在每个步骤之后将其发布到您的服务中,或者等到所有数据在提交之前被收集。

#1


0  

Given the highly customizable needs of wizards, a lot of them have gone by the wayside in favor of creating all of the code by hand. It is safe to assume that the wizard you're talking about here is the ASP.Net WebForm Wizard object? I believe that server control has not been updated in a while.

考虑到向导的高度可定制的需求,他们中的很多人已经放弃了手工创建所有代码的方式。假设您正在讨论的向导是ASP,这是安全的。净WebForm向导对象?我相信服务器控制在一段时间内没有更新。

One thing you could look into doing is building all of the UI elements client side, and then have AJAX / WebAPI endpoints do the data processing. By taking this route, you can easily show/hide/customize the various tabs/steps based on the type of account type being processed (you can get that from the URL, or hidden form field, or something else). You can do a google search for "jQuery wizard builder" or something similar to find libraries out there.

您可以研究的一件事是构建所有UI元素客户端,然后使用AJAX / WebAPI端点进行数据处理。通过使用此路由,您可以很容易地根据正在处理的帐户类型的类型来显示/隐藏/自定义各种选项卡/步骤(您可以从URL,或隐藏的表单字段,或其他东西中获得这些)。您可以使用谷歌搜索“jQuery向导生成器”或类似的查找库。

Decoupling the presentation from the data processing in this regard will give you more flexibility. It still may take a little more than the 700 lines of code, but you will have greater control over what, how, and when the the data is processed for your end user. You can setup the wizard to post to your service after each step, or wait until all data has been collected before making the submission.

将表示与此方面的数据处理分离开来,将给您带来更大的灵活性。它仍然可能需要比700行代码多一点,但是您将会更大的控制什么,如何,以及何时为您的最终用户处理数据。您可以设置向导在每个步骤之后将其发布到您的服务中,或者等到所有数据在提交之前被收集。