Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

After Databind run code 1

Status
Not open for further replies.
What I mean is, the code i run after the bind requires databound data in the table, if the data has not been bound to the table, the code will not execute correctly.

 
What kind of code? Is it VBScript? What kind of DB? What is generating the databind event?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
its an xml document loaded into a dso on the page and vbscript is then called to populate(bind) the table, I have some code afterwards that needs to access the binded tables data, but it happens so fast, the binded data hasnt even loaded, thus errors, I need code like:

Code:
If tablename.databindcomplete = true then
 'continue
End if

 
Have you tried putting On Error Resume Next in right before the code that errors then doing a while loop for Err.Number <> 0? Are you sure that it is a timing issue and that your table is binding at all?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
So did you try something like (pseudocode)

Bind the table
On Error Resume Next
Attempt to access the data
Do While Err.Number <> 0
Attempt to access the data
Loop

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
This is hard to answer without knowing more about what you are trying to do.

There are a number of ways of declaring an XML DSO in IE, the most obvious being the <XML> tag used to create XML Data Islands. Then there is the question of manipulating that object, and much of this requires accessing the XML DOM object embedded inside of the <XML> object.

Note that IE's regular old HTML DOM makes use of the readyState property for any of a large number of element types. It is a String valued property however, not a Long as you might be led to believe. Just to make things more confusing though, there is another readyState property hanging off of the XML DOM object within the <XML> element/object. This one is indeed Long-valued, and the value 4 corresponds to "complete."


Here is a small sample. It traps for completion on changes to the <TABLE> tblPeople by examining readyState within the onreadystatechange event, and it traps for completion on loading of data into the <XML> DSO xmlPeople by catching the event ondatasetcomplete. Using the latter means you don't need to examine readyState - DSOs have a somewhat richer event model than simple HTML elements in IE.

test.htm
Code:
<HTML>
  <HEAD>
    <XML id=xmlPeople>
    </XML>
    <SCRIPT language=VBScript>
      Option Explicit
      Dim strTable

      Sub btnLoadTable_onclick
        xmlPeople.XMLDocument.load "table" & strTable & ".xml"
        If strTable = "A" Then
          strTable = "B"
        Else
          strTable = "A"
        End If
        btnLoadTable.value = "Load Table " & strTable
      End Sub

      Sub xmlPeople_ondatasetcomplete
        MsgBox "Dataset complete" & vbNewline _
             & CStr(Me.recordset.RecordCount) & " rows"
      End Sub

      Sub tblPeople_onreadystatechange
        If Me.readyState = "complete" Then
          MsgBox "Table ReadyState Change: Complete"
        End If
      End Sub

      Sub window_onload
        strTable = "A"
        btnLoadTable_onclick
      End Sub
    </SCRIPT>
  </HEAD>
  <BODY>
    <INPUT type=button id=btnLoadTable>
    <TABLE id=tblPeople datasrc=#xmlPeople border=1>
      <TR>
        <TD>
          <SPAN datafld=name></SPAN>
        </TD>
        <TD>
          <SPAN datafld=number></SPAN>
        </TD>
        <TD>
          <SPAN datafld=age></SPAN>
        </TD>
      </TR>
    </TABLE>
  </BODY>
</HTML>
tableA.xml
Code:
<people>
  <person>
    <name>Fred</name>
    <number>10132</number>
    <age>32</age>
  </person>
  <person>
    <name>Wilma</name>
    <number>10324</number>
    <age>29</age>
  </person>
  <person>
    <name>Barney</name>
    <number>11707</number>
    <age>31</age>
  </person>
</people>
tableB.xml
Code:
<people>
  <person>
    <name>Fred</name>
    <number>10132</number>
    <age>32</age>
  </person>
  <person>
    <name>Wilma</name>
    <number>10324</number>
    <age>29</age>
  </person>
  <person>
    <name>Barney</name>
    <number>11707</number>
    <age>31</age>
  </person>
  <person>
    <name>Betty</name>
    <number>09449</number>
    <age>28</age>
  </person>
</people>
When this page first loads and runs, there isn't any data loaded in xmlPeople. The table tblPeople does complete however, so you'll see an initial MsgBox showing that it has indeed completed. While this MsgBox is pending you'll notice that btnLoadTable is a narrow button, with no caption (value) set, and tblPeople is a tiny, empty table.

The onload event on the document (window) fires and sets strTable to "A" and calls the btnLoadTable_onclick event handler to "prime the pump" (load tableA.xml into xmlPeople and set the button's value).

Loading xmlPeople leads to an eventual ondatasetcomplete event, resulting in a MsgBox telling you how many rows are loaded into xmlPeople. Once data binding to tblPeople is complete, it's readyState goes "complete" producing another MsgBox to that effect.

So far no user interaction has occurred.

Clicking on btnLoadTable causes a "ping pong" loading of xmlPeople with tableB.xml or tableA.xml, which results in more MsgBoxs as xmlPeople finishes loading and tblPeople rebinds and becomes ready. This repeats as long as the user wants to click on btnLoadTable.


Does this help answer any of your questions? DSO loading and operation as well as data binding to HTML elements are asynchronous processes. This means it is necessary to write your script in terms of event handling - you can't just write straightline code and get reliable results. You end up with something that structurally resembles Visual Basic form module code more than simple WSH or ASP script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top