Transaction in Codebehind Only?

  • Thread starter Thread starter localhost
  • Start date Start date
L

localhost

I currently use an ASP.NET transaction by putting the proper
declaration in the .aspx page template. Instead, I would like to put
the transaction declaration only in the code-behind (in one of the
built-in System.Web.UI.Page lifecycle methods).

How can I declare an ASP.NET transaction in the .aspx.cs and *not* in
the .aspx?

Thanks.
 
Hi Localhost,

Based on my understanding, you'd like to set the asp.net page's transaction
declaration in codebehind page rather than in aspx page's @Page directive.

As for this question, I've searched the Documentation on the ASP.NET 's
transaction control and found that this setting is only avaliable in the
@Page directive. This is because the asp.net page's class is dynamically
generated at runtime( in dynamic assembly) which derived from the
codebehind class. And all the attributes set in the @Page directive is
applied on the dynamically generated page class and it's not accessable in
codebehind page class(not exposed as a public property) , that's why we
can't set it in the code behind class.

However, if you do want to apply transaction control in codebehind class,
here are some other means:
1. You can use the .NET buildin transaction apis such as
Transaction.BeginTran , Commit, RollBack.. in the certain function in your
codebehind class when there are transaction required data manipulations.
Here is a tech article discussing on this:
#Transactions in ASP.NET
http://www.c-sharpcorner.com/asp/Code/TransactionsInASPNETDPL.asp

2. Also, the Imports System.EnterpriseServices namespace provide the
functions which help use defind transaction based classes. We can defind
classes derived from ServiceComponent class and apply transaction
attributes on them. Thus, we can encapsulate the transaction required
operations in a certain component class and used in ASP.NET codebehind, do
you think so? Here are also some reference on the .net transaction control:

#Transaction Control
http://msdn.microsoft.com/library/en-us/dnbda/html/bdadotnettransact1.asp?fr
ame=true

#Data Access and Transaction Handling Framework
http://www.codeproject.com/useritems/dac2.asp

Hope also helpful.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Back
Top