0

I have code which will fire on load, and fetch the object based on the ID. It returns null.

<script type = "text/javascript">
   $(function(){
      var TV = $find("FieldTreeViewer");
   });
</script>
<body>
   <telerik:RadTreeView OnClientNodeExpanded="nodePopulating" OnClientNodeClicked="checkLeaf" runat="server" ID = "FieldTreeViewer">
   </telerik:RadTreeView>
</body>

It seems that onload will return null, but if i go into the console and reenter the var TV statement, it will assign it. I figure that the Control was NOT rendered yet. How would I go about making it so that the page renders BEFORE firing the function?

I am aware of asp having onLoad, onInit, etc, but this is purely markup, there is no magic behind the scenes.

I just thought that markup would render, and then when the page finishes loading, i could call a function to reference the control by ID.

4

1 回答 1

1

尝试在 window.load 上执行您的代码,如下所示:

$(window).load(function () 
{ 
    var TV = $find("FieldTreeViewer"); 
});
于 2012-07-31T16:02:01.230 回答