Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1445
How do I find a control that is on a webtab through JavaScript?
posted

My code compiles just find. But when I try to load the page I keep getting this errror...

error CS0103: The name 'grdExpense' does not exist in the current context

Which is making me thing my Javascript is not correct. Because my site worked until I need to add the webtab to it. And now it can not find any of my controls.

What was working was this java...

var grid = $find('<%= grdExpense.ClientID %>');

var ret = grid.get_behaviors().get_editingCore().get_behaviors().get_rowEditingTemplate();

var row = grid.get_behaviors().get_editingCore().get_behaviors().get_rowAdding().get_row();

ToggleValidators(false);

ret.enterEditMode(row);

 

I don't know if its the java that is giving me that error, but like I said everythng is compiling fine.

Thanks for your help.

 

Parents
  • 24497
    Suggested Answer
    posted

    Hi apalcer,

    Your codes should work if grid is a child control in WebTab. Below is example.

    <ig:WebTab ID="WebTab1" runat="server" Height="467px" Width="777px">
     
    <Tabs>
        
    <ig:ContentTabItem runat="server" Text="Tab 1">
         
    <Template>
           
    <ig:WebDataGrid ID="WebDataGrid1" runat="server" AutoGenerateColumns="True" Height="350px" Width="400px">
           
    </ig:WebDataGrid>
         
    </Template>
       
    </ig:ContentTabItem>
       
    <ig:ContentTabItem runat="server" Text="Tab 2"></ig:ContentTabItem>
     
    </Tabs>
    </ig:WebTab>
    <script type="text/javascript">
     
    function findGrid() {
      
    var grid = $find('<%=WebDataGrid1.ClientID %>');
      
    alert('grid:'+grid+':'+grid.get_uniqueID());
     
    }
    </script>
    <input type="button" value="findChild" onclick="findGrid()" />

    However, if you use ContentUrl and child (grid) is located in another aspx, then $find(id) will not work, because child is located in iframe which has different document. If that is the case, then you may find reference to that iframe and use its "window" to get its javascript objects. Something like below:

    // note: you may use server <%=...%> here
    var webtab = $find(clientIdOfWebTab);
    var tab = webtab.getTabAt(1);
    var iframe = tab.get_iframe();
    var win = iframe.contentWindow;
    // note: you cannot use server <%=...%> here, because grid is located in different aspx
    var grid = win.$find(clientIdOfGrid);

     

Reply Children
No Data