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

查看:167
本文介绍了使用一个页面中添加和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.

所以我想我会使用查询字符串来定义我们如何将使用的页面,如果有新的那么一切都将保持不变,如果它用于编辑然后我会改变文本属性的一对夫妇的标签,并显示一些额外的文本框和DropDownLists。

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属性。使其读,如果它是为在网页其值写入到一个视图状态变量。

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 - 使用一个enumuration申报此属性的可能值。你可以声明多种值这个属性像(新建,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天全站免登陆