0

I'm working with ObjectDataSource and FormView control.

In ObjectDataSource I have a type specified, and a method that performs Insert operation. However, once Insert is done, I would like to redirect the user to other page, and I need ID of newly created/persisted object.

So in FormView:

OnItemInserted="OnFormItemInserted"

handler I need to access that ID. But how to pass that id gracefully from ObjectDataSource level? I could use

HttpContext.Current.Items

inside ObjectDataSource handling object, but I don't like it, as my handling type do not know anything about ASP .NET (separation of concerns?).

Thanks

1 Answer 1

2

Have you tried something simple like this:

In your Data object

Update your insert method configured in the ObjectDataSource control to return the generated ID:

public int Insert(string firstName, int lastname)
{
    // return the ID generated by the insert command
    return 4;
}

ASPX code behind

And that's it, in your page where you are handling the Inserted event:

protected void ods_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
    var res = e.ReturnValue.ToString();
    this.lblMessage.Text = res;
    // add your cool additional logic and redirect stuff
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.