Using Named Styles To Update/Modify Multiple O4W Controls At Once (Web)

O4W developers are familiar with the idea of giving unique identifiers to each control so that they can be individually changed during event processing, but did you know that you can also use a named style to change multiple controls all at the same time? Almost every O4W element-defining API has a  styleInfo  parameter, which can contain one or more calls to O4W style APIs (O4WColorStyle, O4WSizeStyle, etc.), and/or one or more  named styles .  A named style (also known in HTML and CSS terms as a  class ) is an identifier that has been defined, perhaps in a  style sheet  that has been loaded into your O4W template or added via an O4WStyleSheet call; it often contains a one or more individual style settings (like background color, foreground color, size, position, etc.) that are applied  en masse  to any element that is assigned to that style name.

 

The O4WUpdate, O4WPlugin, and O4WQualifyEvent APIs can use a named style in place of an explicit ID, and any element that has been assigned to that style name will be updated, or have the plugin applied, or be set for the specified event.  For example, in the following code:

 

O4WTextbox( hello ,   ,   ,  mytb ,  mytb1 ,  tbstyle )

O4WTextbox( world ,   ,   ,  mytb ,  mytb2 ,  tbstyle )

O4WTextbox( goodbye ,   ,   ,  mytb ,  mytb3 ,  tbstyle )

 

You could change the background color to  blue  by the following calls:

 

O4WUpdate( mytb1 ,   , O4WResponseStyle(  ,  , 1 ):O4WColorStyle(  , blue ))

O4WUpdate( mytb2 ,   , O4WResponseStyle(  ,  , 1 ):O4WColorStyle(  , blue ))

O4WUpdate( mytb3 ,   , O4WResponseStyle(  ,  , 1 ):O4WColorStyle(  , blue ))

 

If you had 10 different textboxes that needed a blue background, you would have to repeat the O4WUpdate call 10 times.  However, since all the textboxes have the same style name ( tbstyle ), we could make a single call to affect them all:

 

O4WUpdate( .tbstyle ,   , O4WResponseStyle(  ,  , 1 ):O4WColorStyle(  , blue ))

 

Note the use of a period ( . ) before the named style; this is how O4W identifies a style name (versus an element ID) in these calls.  Also note that the name  tbstyle  doesn t actually define any style information when we begin; although it might have been defined in some style sheet, or via previous O4W style calls, it didn t have to be.  In this case, it was purely used as another way to identify the elements we wanted to group together.

 

Any O4W element can belong to one or more of these named styles; by creatively adding the appropriate style names to your elements, you may be able to reduce the number of individual calls you make to update you elements, resulting in smaller, faster, and more efficient web pages.

  • kb/kb_articles/kb0284.txt
  • Last modified: 2024/01/30 13:36
  • by 127.0.0.1