谁能帮我处理编辑和新模式 [英] Can anyone help me to handle edit and new modes

查看:91
本文介绍了谁能帮我处理编辑和新模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个页面可以添加一些带有文本框的新客户详细信息,以输入数据.
当我单击添加新客户链接时,它将被重定向到"AddNewCustomerPage.aspx".

在另一页中,我有一个客户列表.
当我单击一行并按编辑"按钮时,应将其重定向到相同的"AddNewCustomerPage.aspx"文件,所有文本框均填充有单击的用户数据,并且可以更改文本框值和编辑数据.

我的疑问是如何使用模式状态确认"AddNewCustomerPage.aspx"页面.

要添加新的客户详细信息,它应该处于新模式,所有文本框都为空,以便添加新数据,但是如果处于编辑模式,则这些框将具有相应的用户数据.

我使用QueryString值区分"NEW"和"EDIT"模式.
除了"Querystring"以外,还有其他灵活的方法吗?

这里的客户ID是主键,因此无法传递查询字符串.

预先谢谢您.

Hi there,

I have a page to add new customer details with some textboxes to enter the data.
When I click addnew customer link it will be redirected to the "AddNewCustomerPage.aspx".

In another page I have a list of customers.
When I click a row and press edit button it should be redirected to the same "AddNewCustomerPage.aspx" file, with all the textboxes filled with the clicked user data, and there it is possible to change the textbox values and edit data.

My doubt is how to acknowldege the "AddNewCustomerPage.aspx" page with the status of the mode.

To add new customer details it should be in new mode with all textboxes empty in order to add new data, but if it is in edit mode the boxes will have corresponding user data.

I used QueryString values to differenciate "NEW" and "EDIT" mode.
Is there any other flexible method to do this other than "Querystring"?

Here the customer Id is the primary key so it is not possible to pass through the query string.

Thank You in advance

推荐答案

一种更好的方法是如下实现:

AddNewCustomerPage.aspx.cs中接受QueryString参数"CustomerId".如果参数值(CustomerId)大于0,请使用CustomerId 从数据库中检索客户,然后在文本框中设置客户属性.否则,只需显示文本框即可.

您无需使用"NEW"或"EDIT"模式.

也就是说,您只需在AddNewCustomerPage.aspx.cs
Page_Load中实现以下逻辑
A better way would be to implement as follows:

Accept a QueryString parameter "CustomerId" in AddNewCustomerPage.aspx.cs. If the parameter value (CustomerId) is greater than 0, retrieve the Customer from the database using the CustomerId and set the customer properties in the text boxes. Otherwise, just show the text boxes.

You don''t need to use the "NEW" or "EDIT" mode.

That is, you just implement the following logic in the Page_Load of AddNewCustomerPage.aspx.cs

int CustomerId = 0;
if(Request.Params["CustomerId"] != null)
{
    CustomerId = Convert.ToInt32(Request.Params["CustomerId"]);
}
if(CustomerId > 0)
{
    Customer customer = GetCustomerFromDB(CustomerId)
    PopulateUI(customer);
}


这篇关于谁能帮我处理编辑和新模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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