使用一页在 ASP.NET 中添加和编辑项目 [英] Use one page for adding and editing an item in ASP.NET

查看:16
本文介绍了使用一页在 ASP.NET 中添加和编辑项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这里的问题不清楚.

I don't think the question is clear here.

我的系统中有 19 种类型的项目.我有 19 页,每页允许我添加特定类型的新项目.

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.

所以我想我会使用 QueryString 来定义我们将如何使用页面,如果是新的,那么一切都将保持不变,如果它用于编辑",那么我会改变几个标签的文本属性,并显示一些额外的文本框和下拉列表.

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.

感谢您的时间=)

推荐答案

1- 声明页面或类型的 InstanceState 属性.如果它用于页面,则使其读取并将其值写入 ViewState 变量.

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- 使用枚举来声明此属性的可能值.您可以为此属性声明许多值,例如 (New, OnEdit, OnRead ).

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- 声明一些其他布尔属性以帮助您轻松自定义布局,例如(InstanceIsNew、InstanceIsOnRead、InstanceIsOnEdit ..).这些属性依赖于 InstanceState 属性来返回它们的值.

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- 将您的布局项绑定到这些属性,以根据它们的值显示、启用以及您需要对布局项执行的任何其他操作.

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- 在适当的事件上更改 InstanceState 的值以更改您的布局.

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.

这篇关于使用一页在 ASP.NET 中添加和编辑项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆