使用一个页面在 ASP.NET 中添加和编辑项目
我认为这里的问题还不清楚。
简而言之,我的系统中有 19 种类型的项目。我有 19 页,每一页都允许我添加特定类型的新项目。
“添加新项目”页面和“编辑现有项目”页面彼此非常相似。我所需要的只是隐藏/显示几个控件。
所以我想我应该使用QueryString
来定义我们将如何使用该页面,如果是新的,那么一切都将保持不变,如果它用于“编辑”,那么我将更改文本属性对于几个标签并显示一些额外的文本框和下拉列表。
我可以通过多种方式做到这一点,但这会很混乱。我希望有人能提出一种方法来做到这一点,并保持我良好的设计和架构。
感谢您的宝贵时间=)
I don't think the question is clear here.
Simply I have 19 types of items in my system. and I have 19 pages each one allow me to add a new item of specific type.
The "Add New Item" page and the "Edit an existing Item" page, are very similar from each other .. all what I need is to hide/show a couple of controls.
so I thought I'd use QueryString
to define how we'll be using the page, if new then everything will remain the same and if it's used for "editing" then I'll change the Text properties for a couple of labels and show some extra TextBoxes and DropDownLists.
I could do this in a several ways but it will be a mess. I was hoping that someone could propose a way to do this keeping in my a good design and architecture.
Thanks for your time =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
让一个页面根据参数进行添加/编辑的另一种方法是让两个不同的页面共享提供通用 UI 的 UserControl。例如,如果您有 CustomerAdd.aspx 和 CustomerEdit.aspx,则可以共享包含名称、地址等文本框的 CustomerProperties.ascx 控件。
An alternative to have one page that does both add/edit depending on parameters is to have two distinct pages that share a UserControl that provides the common UI. For example, if you have CustomerAdd.aspx and CustomerEdit.aspx thjey could share a CustomerProperties.ascx control that has textboxes for Name, Address, etc.
您的页面上可以有两个面板,一个用于添加控件,一个用于编辑控件,并且两个面板都设置为visible=false。
然后您可以执行 page.aspx?do=add 或 page.aspx?do=edit 然后使用:
You could have two panels on your page, one for the add controls and one for the edit controls with both set visible=false.
Then you can either do page.aspx?do=add or page.aspx?do=edit and then use:
1- 声明页面或类型的 InstanceState 属性。如果它是针对页面的,则让它读取其值并将其写入 ViewState 变量。
2- 使用枚举来声明该属性的可能值。您可以为此属性声明许多值,例如(New、OnEdit、OnRead)。
3-声明一些其他布尔属性来帮助您轻松自定义布局,例如(InstanceIsNew、InstanceIsOnRead、InstanceIsOnEdit ..)。这些属性依赖于 InstanceState 属性来返回它们的值。
4- 将您的布局项绑定到这些属性,以根据其值显示、启用以及您需要在布局项上执行的其他操作。
5- 更改相应事件上的 InstanceState 值以更改布局。
注意:当您处理第一页时,您可能会发现它有点复杂。但一旦你理解了它的逻辑,你就可以轻松快速地将其应用到其他人身上。
1- Declare an InstanceState property for the page or the type. Make it read and write its value to a ViewState variable if it is for the page.
2- Use an enumuration to declare the possible values of this property. You can declare numerous of values to this property like (New, OnEdit, OnRead ).
3- Declare some other boolean properties to help you in customising your layout easily like (InstanceIsNew, InstanceIsOnRead, InstanceIsOnEdit ..). Those properties depend on the InstanceState property to return their values.
4- Bind your layout items to those properties to show, enable and what ever else you need to do on your layout items according to their values.
5- Change the value of the InstanceState on the appropriate events to change your layout.
NOTE: You might find it a bit complicated when you work on it for the first page. But once you understand the logic of it you can apply it easy and fast on the others.