Keep User Entered Data on Failed Save

Keep User Entered Data on Failed Save

Old forum URL: forums.lhotka.net/forums/t/2949.aspx


JoeCourtney posted on Monday, May 28, 2007

I'm new to CSLA 2.1 and ASP.NET, so I have been use ProjectTracker (PTWeb) as a guide for my application's ASP.NET functionallity.  (Taking ResourceEdit for example:)  I notice when an existing Resource is updated and rules are broken then the ResourceEdit page keeps the changes made by the user in the TextBoxes.  However, when a new Resource is being added and rules are broken, then TextBox information is cleared in all TextBoxes.  I wish to keep the entered information on an insert (new Resource) eventhough it breaks rules.

For the life of me, I have not been able to figure out why the data is not kept in the TextBoxes in this situation.  At first, I thought it might be in the SaveResource section and the currentObject, but it seems to be something on the ProjectEdit.aspx form that is different on the post between Update and Insert.

Can anyone point me in the right direction for desired functionallity?

Thanks.

 

RockfordLhotka replied on Tuesday, May 29, 2007

This is due to the way the DetailView control works. It handles update and insert operations very differently, and (imo) Microsoft did a terrible job of supporting the insert scenario. They simply didn't provide a good way to provide default values for new items.

I thought I had code in both ProjectEdit and ResourceEdit to address this, but maybe I only added the code to ProjectEdit.

In any case, there was a thread on here a long time ago about this issue - of getting default values into DetailView for an insert. The solution I put into ProjectEdit is not pretty, but it does work...

JoeCourtney replied on Thursday, May 31, 2007

Thanks Rocky, Project does retain the entered information...  The thread at http://forums.lhotka.net/forums/permalink/3684/2539/ShowThread.aspx#2539 helped me out.

All I had to do was add e.KeepInInsertMode = true to the DetailsView_ItemInserted event:

protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
 City city = GetCity();
 if (!city.IsNew)
 {
  Response.Redirect("CityEdit.aspx?id=" + city.Id.ToString());
 }
 else
 {
  e.KeepInInsertMode = true;
 }
}

Copyright (c) Marimer LLC