Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3223764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:08:42+00:00 2026-05-17T16:08:42+00:00

I have a page where I use two ASP DetailsView controls to render data

  • 0

I have a page where I use two ASP DetailsView controls to render data from two different, but related, LinqDataSource objects. My primary table is represented in the first DetailsView/LinqDataSource set, and I use the LinqDataSource’s built-in update functionality to persist changes when the DetailsView is in edit mode. The primary table here represents a “Contact” entity (i.e. a person or organization and their contact info).

The second DetailsView renders data from a cross-reference table that associates a Contact with one or more “tags”. The tag definitions come from another table, so the cross reference table just associates a Contact ID with a Tag ID; standard many-to-many type scenario.

I have updates to the Tag Xref working properly; when tags are added or removed from a contact, the appropriate rows are inserted or deleted from the Xref table. This is accomplished not via the LinqDataSource, but by handling the ItemUpdating event for the tags DetailsView and using a DataContext to manually process the inserts and deletes.

So the Contact and the Contact’s tags can be updated individually. Trouble is, I need updates to Contact and to the Tags Xref to happen together in a single transaction. I have the two DetailsView controls linked so that when the user clicks “Update” for the first control, it triggers an update on the second. But the first DetailsView uses its bound LinqDataSource to do the update, which has its own DataContext. Attempts to “share” the DataContext between my manual update and the LinqDataSource result in ObjectDisposed exceptions.

I feel I’m missing something obvious. Sharing DataContext objects seems like a slippery slope. Is there a way I can run a transaction on the page that would enclose both operations?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:08:42+00:00Added an answer on May 17, 2026 at 4:08 pm

    You’ve got the right approach. Create one DataContext object sometime earlier in the page lifecycle (I typically use the constructor). Add a ContextCreating handler to both LinqDataSources. In the handler, assign your DataContext to the event’s ObjectInstance property (see also: this answer). Create the transaction in, say, the ItemUpdating event:

    myDataContext.Connection.Open();
    myDataContext.Transaction = myDataContext.Connection.BeginTransaction();
    

    Now here comes the tricky step—where you were getting tripped up before. By default, the LinqDataSource will dispose of its DataContext when it finishes submitting changes. You need to override this behavior by adding a ContextDisposing event handler. In the handler, set the event’s Cancel property to true.

    Now after the work is complete, you can either commit or rollback the transaction. (Don’t forget to dispose of the transaction.) Finally, you can dispose of the DataContext in Page_Unload.

    P.S. If you’re using DynamicData, be aware that the DynamicDataManager adds its own handler to ContextCreating that creates a new DataContext, thereby avoiding your explicitly created transaction. Annoying.


    Alternatively, you can use TransactionScope. Simply create a new object before the work needs to be done, then call Complete when the work is done. There’s way too much magic going on there for my tastes though. I prefer to use the more explicit DataContext transactions when I can.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use page methods in my asp.net page. I have enable
Using two ScriptManagers(ASP.Net and Telerik) will effect the page performance ? I have both
I have two nested repeaters in my *.aspx page. <asp:Repeater runat=server id=rptMain> <ItemTemplate> <h1><%#DataBinder.Eval(Container.DataItem,
I have SP that selects data from a table with two columns like this
I have found a problem with use JQuery timeout, i have a page with
Okay, my dilemma is this. I have an admin page that I use to
If you have several div s on a page, you can use CSS to
I have a page upon which a user can choose up to many different
I am creating a GridView/DetailsView page. I have a grid that displays a bunch
I have two ASP.NET sites that are used for managing patient information. One application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.