Click here to Skip to main content
15,891,907 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
Posted
Updated 28-Oct-10 23:10pm
v3
Comments
Dalek Dave 29-Oct-10 5:10am    
Edited for Grammar and Readability.

1 solution

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);
}
 
Share this answer
 
v2
Comments
senguptaamlan 30-Aug-10 9:37am    
Reason for my vote of 5
Good approach
Dalek Dave 30-Aug-10 12:10pm    
Good answer.
[no name] 30-Aug-10 13:16pm    
Perfect as per requirements.
Rajesh Anuhya 29-Oct-10 6:27am    
Good Answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900