Official Content

Warning: Since GeneXus 16, it is strongly recommended to create a User Control object instead of creating a Web User Control.

This is intended to briefly explain how the User Control works for a better understanding of the topic.

The questions addressed here are:

  • How does a user control work?
  • How does GeneXus render a user control at runtime?

The answers are covered in the next 3 steps which take place when generating a page that uses a user control.

1. DIV placement

When rendering the page that has a user control, GeneXus will first insert a DIV (in the place where the user control is located) and will then assign the code generated by the control (see step 3) as the innerHtml of the DIV.

2. Runtime render class creation and properties initialization.

After placing the DIV, GeneXus will create an instance of the class defined in the runtime render class. Then, the control properties will be assigned according to the values set at design time. In the case of data bound properties, GeneXus will call its "SetValueData" method passing the attribute, variable or SDT bound to that property.
You can then use that attribute, variable or SDT from the javascript code.

3. Call show method

Finally, after all the properties have been initialized, the show method of your control will be invoked. This method will be in charge of producing all the necessary HTML code to display your control. This HTML code must then be assigned to the DIV that GeneXus created in step 1 using the "setHtml" function:

//Hello World runtime render file sample
 
this.show = function(data)
 {
  ///UserCodeRegionStart:[show] (do not remove this comment.)
  var buffer= '<font face="' + this.FontFace + '" color="' +  this.FontColor + '" size="' + this.FontSize + '">Hello World!!!</font>';   
  this.setHtml(buffer);   

  ///UserCodeRegionEnd: (do not remove this comment.)
 }

It is important to remark that the steps described above are automatically "executed" by GeneXus, that is to say, the programmer is only responsible for generating the HTML code of the control (inside the show method). After that, the programmer must assign this code to the DIV as explained above.

You may have also noticed that within the show method, you can do as many things as you wish. That is to say, you can use external javascripts libraries, create flash controls and so on.

See also User controls : Loading external javascript resources to understand other issues about using external dependencies.

Check the User Controls samples for more details.

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant