prevent PerformSelect on page PostBack?

Posts   
 
    
Posts: 7
Joined: 13-Sep-2006
# Posted on: 26-May-2009 05:38:22   

I am binding LLBLGenObjectDataSource2 to form view with EnableViewState = true, CacheLocation = Session, LivePersistence=false

On the UPDATE click, the PerformWork() event call the BL to save the data. If error occur in ValidateEntityBeforeSave(), the BL throw ORMEntityValidationException back to PerformWork() then the error message display on the form fine.

The problem I am having is the form data also get reset back to original data. This is caused by PerformSelect() being automatically called on the page Post Back.

I need the FormView to display current edited data. If a validation error occur, let the user correct the data, resubmit to save.

I appreciate any suggestion you can give...

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-May-2009 07:46:41   
David Elizondo | LLBLGen Support Team
Posts: 7
Joined: 13-Sep-2006
# Posted on: 26-May-2009 20:04:49   
  • LLBLGen 2.6 Final, released on June 6th, 2008
  • VS 2008, .NET 3.5, SP1

ASPX Code

-- LLBLGen ODS --

<llblgenpro:LLBLGenProDataSource2 ID="ldsData" runat="server" AdapterTypeName="iData.DAL.DatabaseSpecific.DataAccessAdapter, iClaim.DALDBSpecific" DataContainerType="EntityCollection" EnableViewState="true" EntityFactoryTypeName="iData.DAL.FactoryClasses.MyDataEntityFactory, iClaim.DAL" onperformwork="ldsData_PerformWork" CacheLocation="Session" LivePersistence="False" onperformselect="ldsData_PerformSelect"> </llblgenpro:LLBLGenProDataSource2>

-- FormView --

<asp:FormView runat="server" ID="fvFROI" DataKeyNames="ID" DataSourceID="ldsData" DefaultMode="Edit" >

<EditItemTemplate> <asp:TextBox ID="cName" Text='<%# Bind("Name") %>'/>

  -- _99 more fields bind to ODS similar to above_ --

  <asp:Button ID="btnSubmit" 
       OnClick="btnSubmit_Click" 
       CommandName="Update" runat="server" Text="Submit" />

</EditItemTemplate>

.CS Code

protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { _id = 1; // use record 1 for testing ldsData.Select(); } }

protected void ldsData_PerformSelect(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs2 e) { if (null != _id) ldsData.EntityCollection = DataManager.GetDataById((int)_id); }

protected void ldsData_PerformWork(object sender, PerformWorkEventArg2 e) { try { DataManager.Update(e.Uow); } catch (ORMEntityValidationExection ex) { // assign error msg to lErrorMsg; // **What settings can I do in here to prevent the PerformSelect() ** // get triggered after this routine completed? } }

NOTE:

If I add a regular button (no commandName) in the formView. OnClick, the page get post back and PerformSelect() does not get execute. Only the Update command type button which triggered the PerformWork(). After PerformWork() completed, with exception throw, PerformSelect() get call regardless.

Should I do the entity validation in ldsData.EntityUpdated() event. If error occur, set e.cancel = true. Don't implement the ValidateEntityBeforeSave().

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 27-May-2009 10:04:28   

LLBLGen 2.6 Final, released on June 6th, 2008

This is not the LLBLGen Pro runtime library version, please check the link posted by David (daelmo). But anyway I think you have an old version, and it might be a good idea to try the latest build.

Should I do the entity validation in ldsData.EntityUpdated() event. If error occur, set e.cancel = true. Don't implement the ValidateEntityBeforeSave().

It depends on what you're validating. But for Databinding issues I always try to have validations inside the EntityUpdating/EntityInserting events of the LLBLGen Pro DataSource in case I'm using LivePersistence, or directly inside the PerformWork event if I'm disabling LivePersistence. Whether or not I'm having validations at a lower level.

Posts: 7
Joined: 13-Sep-2006
# Posted on: 27-May-2009 17:16:40   

Walaa wrote:

LLBLGen 2.6 Final, released on June 6th, 2008

This is not the LLBLGen Pro runtime library version, please check the link posted by David (daelmo). But anyway I think you have an old version, and it might be a good idea to try the latest build.

Should I do the entity validation in ldsData.EntityUpdated() event. If error occur, set e.cancel = true. Don't implement the ValidateEntityBeforeSave().

It depends on what you're validating. But for Databinding issues I always try to have validations inside the EntityUpdating/EntityInserting events of the LLBLGen Pro DataSource in case I'm using LivePersistence, or directly inside the PerformWork event if I'm disabling LivePersistence. Whether or not I'm having validations at a lower level.

The current runtime lib ver for SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll is 2.6.8.624 and I just upgraded it to 2.6.9.511

So, after I catch the validation exception in PerformWork(), what do I need to do to prevent PerformSelect get trigger? Can I do something similar to the ItemUpdating() {e.Cancel = true;} in PerformWork() ?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-May-2009 05:09:52   

tranfamily35 wrote:

So, after I catch the validation exception in PerformWork(), what do I need to do to prevent PerformSelect get trigger? Can I do something similar to the ItemUpdating() {e.Cancel = true;} in PerformWork() ?

Yes. You need to cancel the operation on the datasource and keep the control in EditMode. Here is a example snippet (from the Validation Example, at download section of the site):

/// <summary>
/// Handles the EntityUpdating event of the ProductsDS control.
/// Used to trap the entity fields errors at the current ProductEntity
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="SD.LLBLGen.Pro.ORMSupportClasses.CancelableDataSourceActionEventArgs"/> instance containing the event data.</param>
protected void ProductsDS_EntityUpdating(object sender, CancelableDataSourceActionEventArgs e)
{
    // the entity involved
    ProductEntity entityToEvaluate = (ProductEntity)e.InvolvedEntity;

    // Retrieve the fields errors from the entity. This will return a semicolon-separated list containing the info.
    string errors = entityToEvaluate.GetEntityFieldsErrors();

    // there are errors, so cancel the update so the user can fix them.
    if (errors != string.Empty)
    {
        e.Cancel = true;
        ShowEntityErrors(errors);
    }
    else
    {
        HideEntityErrorControls();
    }
}


/// <summary>
/// Handles the RowUpdated event of the ProductsGridView control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewUpdatedEventArgs"/> instance containing the event data.</param>
protected void ProductsGridView_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
    // there's errors, so force the gridView to stay in editMode.
    if (blProductEntityErrors.Visible)
    {
        e.KeepInEditMode = true;
        Message.Visible = false;
    }
}
David Elizondo | LLBLGen Support Team
Posts: 7
Joined: 13-Sep-2006
# Posted on: 28-May-2009 17:31:12   

Thank you for your help.