使用一个页面在 ASP.NET 中添加和编辑项目

发布于 2024-11-01 18:47:50 字数 329 浏览 0 评论 0原文

我认为这里的问题还不清楚。

简而言之,我的系统中有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奈何桥上唱咆哮 2024-11-08 18:47:50

让一个页面根据参数进行添加/编辑的另一种方法是让两个不同的页面共享提供通用 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.

ㄟ。诗瑗 2024-11-08 18:47:50

您的页面上可以有两个面板,一个用于添加控件,一个用于编辑控件,并且两个面板都设置为visible=false。

然后您可以执行 page.aspx?do=add 或 page.aspx?do=edit 然后使用:

        If Request.QueryString("do") = "add" Then
            pnlAdd.Visible = true
        ElseIf Request.QueryString("do") = "edit" Then
            pnlEdit.Visible = true
        Else
           'Do some error handling.
        End If

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:

        If Request.QueryString("do") = "add" Then
            pnlAdd.Visible = true
        ElseIf Request.QueryString("do") = "edit" Then
            pnlEdit.Visible = true
        Else
           'Do some error handling.
        End If
可爱咩 2024-11-08 18:47:50

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文