次の方法で共有


Writing Transaction Events

A script itself cannot determine whether a transaction has succeeded or failed. However, you can write events that are called when the transaction commits or aborts. For example, suppose you have a script that credits a bank account, and you want to return different pages to the user depending on the status of the transaction. You can use the OnTransactionCommit and OnTransactionAbort events to write different responses to the user.

<%@ TRANSACTION=Required %> 

<% 
  'Buffer output so that different pages can be displayed. 
  Response.Buffer = True 
%> 

<HTML> 
  <BODY> 
  <H1>Welcome to the online banking service</H1> 


  <% 
    Set BankAction = Server.CreateObject("MyExample.BankComponent") 
    BankAction.Deposit(Request("AcctNum")) 
  %> 

  <P>Thank you.  Your transaction is being processed.</P> 
  </BODY> 
</HTML> 

<% 
  'Display this page if the transaction succeeds. 
  Sub OnTransactionCommit() 
%> 
  <HTML> 
    <BODY> 

    Thank you.  Your account has been credited. 

    </BODY> 
  </HTML> 

<% 
  Response.Flush() 
  End Sub 
%> 

<% 
  'Display this page if the transaction fails. 
  Sub OnTransactionAbort() 
    Response.Clear() 
%>        
  <HTML> 
    <BODY> 

    We are unable to complete your transaction. 

    </BODY> 
  </HTML> 
<% 
    Response.Flush() 
  End Sub 
%>