| By Frederick Koh, Li, Zhao | Article Rating: |
|
| August 30, 2007 03:00 PM EDT | Reads: |
11,139 |
The sharing of DataWindow data across sessions is done using existing DataWindow.NET and ASP.NET features. The data to be shared across sessions are stored in DataStores that are, in turn, cached in the ASP.NET application's single instance of HttpApplicationState. The DataStores are indexed by the DataWindow name prefixed by "SharedDW_" in the case of shared DataWindows and "SharedDDDW_" in the case of shared Dropdown DataWindows.
For a given shared DataWindow, the corresponding DataStore is initialized during the first invocation of Retrieve of any DataWindow Control that has the specified DataWindow as its DataObject. The initialization includes an invocation of Retrieve on the DataStore.
Once the DataStore has been initialized, the ShareData mechanism is used to share data between the DataStore and the DataWindow Control. Subsequent invocations of Retrieve on other DataWindow Controls that has the specified DataWindow as its DataObject will trigger only the ShareData mechanism. The .NET concurrency services are used during both the initialization and ShareData phases.
The use of the ShareData facility of the DataWindow explains the restrictions on DataWindow Controls that make use of this Web application-level sharing of data.
Event Handling & Latency
In the WebForm deployment version of the DataWindow, the following events are triggered by user action on the client side:
- ItemChanged
- ItemError
- ItemFocusChanged
- RowFocusChanging
- RowFocusChanged
- ButtonClicked
- ButtonClicking
- Clicked
- DoubleClicked
- RButtonDown
To execute the corresponding event script on the server-side, the DataWindow uses the ASP.NET postback mechanism. There's no one-to-one correspondence between an event triggered and a postback. In most situations, events and related data are accumulated before an actual postback. To give an example, suppose a user finished entering data in the edit column and clicks on an item on another row. This causes the following events to be triggered:
- ItemChanged
- Clicked
- RowFocusChanging
- RowFocusChanged
- ItemFocusChanged
When No Event Scripts Are Defined for a Particular Event
When user action triggers an event for which there are no corresponding
event scripts on the server side, no postback occurs. For example, if
the script for the ItemError event is defined (and no others), postback
occurs only if the user enters invalid data.
Under the Covers - How DataWindow Event Scripts Control Client-side JavaScript Event Handlers
The WebForm version of the DataWindow is actually nothing other than a
subclass of the DataWindow.NET WebDataWindow control. The client-side
programming capabilities of the WebDataWindow are used to control the
client-side JavaScript event handlers. Depending on what PowerScript
(server-side) event handlers are defined, different client-side
handlers are attached. The "PBDataWindow.js" file contains all these
handlers. The choice of handlers to attach to each event follows the
logic described in Table 1. Also indicated in the table is whether each handler will cause a postback.
The ClientEventXxy properties of the WebDataWindow have also been exposed should the need to override the ones in "PBDataWindow.js" arise. The names of the properties have however been changed - please refer to Table 2. The signatures of these handlers and the effects of their return values are documented in the DataWindow.NET references. You can also find this information in Chapter 3 of "Deploying Applications and Components to .NET" in the PowerBuilder 11.0 documentation.
This ability to override client-side event handler allow user-defined client-side handlers to circumvent postbacks according to user-defined criteria. For example, it's possible to define a client-side ItemChanged event handler that posts back only if the column isn't a radio button or checkbox - the event handler can do this by returning immediately on determining that the source of the event is a checkbox or radio button - on determining that it's not a checkbox or radio button, the handler should invoke the pre-defined handler (listed in Table 1).
An Example
Suppose you do data validation for some
columns in ItemChanged. You don't want postbacks for columns that
aren't validated by ItemChanged.
First, create a text file to contain the JavaScript function that will serve as the new event handler. Look up Table 1 for the function used as the handler for ItemChanged. You'll need to call this function in the function you're writing.
Next, look up the signature of the client-side event handler in the DataWindow.NET reference.
Your function should check whether the source of the events is the columns that need validation by the ItemChanged event. If so, invoke the pre-defined ItemChanged event handling function you found. If not, return without further processing (See Listing 1).
//Start MyScriptFile.js
function MyItemChanged(sender, rowNumber, columnName,newValue)
{
if(columnName == "emp_id")
{
// The default function is invoked
return PBDataWindow_ItemChangedReject(sender,rowNumber, columnName, newValue)
}
else
{
//do nothing
}
}
Listing 1 Client-side ItemChanged event handler
In PowerScript you'll have to add some code to the constructor event of the DataWindow control in question. Set your JavaScript function as the client-side event handler for ItemChanged (see Figure 6).
Then, as the last step, deploy, remembering to add the newly created JavaScript source file to the deployment (see Figure 7).
Refactoring
An alternative to using client-side
JavaScript to reduce postback is to change how your DataWindow handles
events. Try replacing the functionality in these event handlers with
the following alternative approaches:
- Clicked - avoid it entirely. If possible, use a control like a CommandButton and put functionality there.
- RowFocusChanging - use a row-level CommandButton and put the event handler in ButtonClicking.
- RowFocusChanged - use a row-level CommandButton and put the event handler in ButtonClicked.
- ItemFocusChanged - a void it entirely. If possible, use a control like a CommandButton and put functionality there.
- ItemChanged - avoid it entirely. If possible, use a control like a CommandButton and put functionality there.
What's In Store
As a further enhancement to our
event handling architecture and response to potential latency issues,
we are exploiting ASP.NET AJAX technology in PowerBuilder 11.1. What
this would mean for applications is better performance for DataWindow
event handling - while events would continue to be processed on the
server. The DataWindow would only be re-rendered if the DataWindow were
modified.
Conclusion
One of the objectives of PowerBuilder
11.0 is to let you deploy your existing PowerBuilder applications as
ASP.NET Web Applications with as little code change as possible.
Because the Web is a very different environment from the client/server
architecture that your application evolved in, you'll want to continue
to evolve it in its new environment. We hope what you find here will
help you with that.
Published August 30, 2007 Reads 11,139
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Frederick Koh
Frederick Koh is a Staff Engineer at Sybase, Inc., and has been a member of the PowerBuilder and DataWindow.NET development team since 2005. Frederick has over 14 years of IT industry experience.
More Stories By Li, Zhao
Li, Zhao is a senior engineer at Sybase, Inc., and has been a member of the PowerBuilder and DataWindow.NET development team since 2006. Li, Zhao has over 10 years of IT industry experience. Li, Zhao has written articles for various computer science conferences and journals.
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- How PowerBuilder Got Its Groove Back
- The Cloud Has Cross-Border Ambitions
- Ulitzer Named "New Media" Partner of Greatly Anticipated iStrategy Event in Berlin
- Risks and Enterprise Mobility?
- Steps for Success in Enterprise Mobility?
- Are Mobile Luddites Resisting Mobility?
- Hot Event in Santa Clara Becomes Cool with the iPhone
- The Difference Between Web Hosting and Cloud Computing
- Sybase CTO to Speak at 4th International Cloud Computing Expo
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- Five Reasons to Choose a Private Cloud
- Seeding The Cloud: The Future of Data Management
- The Threat Behind the Firewall
- Economy Drives Adoption of Virtual Lab Technology
- Tips for Efficient PaaS Application Design
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- Where Are RIA Technologies Headed in 2008?
- PowerBuilder History - How Did It Evolve?
- The Top 250 Players in the Cloud Computing Ecosystem
- Custom Common Dialogs Using SetWindowsHookEx
- DDDW Tips and Tricks
- OLE - Extending the Capabilities of PowerBuilder
- DataWindow.NET How To: Data Entry Form
- Book Excerpt: Sybase Adaptive Server Anywhere
- Sybase ASE 12.5 Performance and Tuning
- Working with SOA & Web Services in PowerBuilder
- Office 2003 Toolbar: A New Look For Your Old PowerBuilder App
- Dynamically Creating DataWindow Objects

































