DHTML Form rendering and activating a pageframe page


Web Connection's DHTML rendering from VFP forms supports pageframes. However, it does not automatically select the active page when rendering (this will be addressed in the next release). Even if it did handle the active page you'd possibly have an issue with the fact that you probably don't select the page of a pageframe as you would if the form ran interactively.

So how do you get the form to start up with a particular page selected. Here's how you do it:

DO FORM Pages NAME loForm LINKED

oHTMLForm = CREATE('wwHTMLForm',loForm,Response)

*** Load data into the form
loForm.LoadCust(lcPk)

*** Now let's force the form to Page 2
oHTMLForm.cFormOnLoadCode = THISFORM.cFormOnLoadCode + CR + ;
                            'btn_pgfPages_Page2_OnClick()'

oHTMLForm.ShowContainer()

RETURN

wwHTMLForm has a property called cFormOnLoadCode which fires when the HTML document is first loaded (actually after the HTML has loaded, but before the form becomes active - the code goes into the Browser's Window_OnLoad() event). If you need to attach any script code that needs to happen when the page loads this is the place to do it. Here I'm telling it to simulate a Click on the second page to force it to activate.

FWIW, there's another code hook that you can attach script code to: cExitFormHTML. Use this snippet to attach any VBScript or JavaScript events which can be accessed through method names like Sub Button1_OnClick() etc.

If you want to fix the pageframe rendering issue at the framework level you can add the following code into wwHTMLForm's InsertObject method:

   CASE lcBaseClass = 'PAGEFRAME'
      * Show the Outline
      loHTMLObject=CREATE('wwHTMLPageFrame',loObject,THIS.oHTML)
      *** Actually gen the HTML (into the loHTML object)
      loHTMLObject.GetHTML()
      
      *** Now render each page as a container
      FOR x=loObject.PageCount TO 1 STEP -1
        loPage = loObject.Pages[x]
        loHTMLObject=CREATE('wwHTMLForm',loPage,THIS.oHTML,.F.)
        loHTMLObject.nTableBorder = 0
        loHTMLObject.nValueType = THIS.nValueType

        *** Actually gen the HTML (into the loHTML object)
        loHTMLObject.ShowContainer(.T.,IIF(x=1,.F.,.T.))
        
        *** Add any OnLoad from the container code to the form
        IF !EMPTY(loHTMLObject.cFormOnloadCode)
          THIS.cFormOnLoadCode = THIS.cFormOnloadCode + CR + ;
                                loHTMLObject.cFormOnloadCode
        ENDIF
        IF x = loObject.ActivePage and loObject.ActivePage > 1
           THIS.cFormOnLoadCode = THIS.cFormOnloadCode + CR + ;
                               'btn_' + loHTMLpgfObject.cFullObjectName + ;
                               '_' + loPage.Name + '_OnClick()'
        ENDIF
      ENDFOR

This code checks for the active page and if found adds the pageframe click into the form's load code. With this in place you can now simply set the active page via code then let the renderer handle display of the proper page:

loForm.pgfPage.ActivePage = 2
loHTMLForm.ShowContainer()


Last Updated: 11/11/98