views:

95

answers:

4

In many applications the "create new record" and "edit existing record" forms are very similar or even identical.

Is it a good idea to use the same code unit for these two (same winform or html page or whatever) or would it cause trouble in the long run?

+3  A: 

Well, I guess it's a matter of personal preference... If you want both forms to look the same, it looks like a good idea. You just have to make the fields editable and add a few buttons when you're in edit mode

Thomas Levesque
Or, alternatively (depending on application and domain of course), have a "new" button that creates a new record, then opens this new record in edit mode, thus collapsing the need for two forms entirely.
Matthew Scharley
+3  A: 

I think that it would be more favorable to use the same code unit for creating and editing a record. Re-use of code is more preferable to me. Especially if you want to change the look of the form or add additional fields, you'd want to have only one place to update.

-JFV

JFV
+2  A: 

Have you considered using a user control? This would allow you to keep the form elements consistent between both pages? this solution is valid for both WinForms, WebForms, and ASP.NET MVC.

Simply design the form as you would normally with just the form elements (textboxes, labels, alignment, fieldsets, borders, etc), and then both pages can read the properties that you expose in the user control (i.e. create a get property for each form element)

So when trying to read the property of txtFirstName, simply refer to the userControl.FirstName

p.campbell
+2  A: 

Also if you are using MVC and Linq to SQL - you can create a "partial form" that will render both create and edit.

You use them on both Views - Create and Edit.

Have a look at this if you can use MVC http://weblogs.asp.net/scottgu/archive/2009/03/10/free-asp-net-mvc-ebook-tutorial.aspx

Really good explanation of CRUD using the new 3.5 and MVC.