This is a migrated thread and some comments may be shown as answers.

[Solved] ascx onload

1 Answer 211 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
John Grymonprez
Top achievements
Rank 1
John Grymonprez asked on 02 Apr 2009, 11:35 AM
I have an ascx page that has a couple of RadComboBox controls. Those comboboxes have a RadTreeView template populated with some values. When the user clicks on the nodes the combobox's text changes. This all works pretty well. My problem however is that when the user submits the form, and he missed one or more fields, the checked nodes remain checked (which is a good thing) but the text in the combobox gets cleared again. I need to fire an onload event in which I can run through the treeviews and set the text of the comboboxes.

The code that I use to try to get this effect:
function addEvent(evnt, elem, func)  
    { 
        if (elem.addEventListener) // W3C DOM 
            elem.addEventListener(evnt,func,false); 
        else if (elem.attachEvent) // IE DOM 
        {  
            var r = elem.attachEvent("on"+evnt, func); 
        } 
        return r; 
         
    } 
    addEvent(window.onload,load()); 
function load() 
    { 
        var comboClass = $find("<%= rcClass.ClientID %>"); 
        var comboCountry = $find("<%= rcCountry.ClientID %>"); 
        var comboTm = $find("<%= rcTrademark.ClientID %>"); 
        var comboYearFrom = $find("<%= rcYearFrom.ClientID %>"); 
        var comboYearTo = $find("<%= rcYearTo.ClientID %>"); 
        var comboType = $find("<%= rcType.ClientID %>"); 
         
        var treeClass = comboClass.get_items().getItem(0).findControl("TreeClass"); 
        var treeCountry = comboCountry.get_items().getItem(0).findControl("TreeCountry"); 
        var treeYearTo = comboYearTo.get_items().getItem(0).findControl("TreeYearTo"); 
        var treeYearFrom = comboYearFrom.get_items().getItem(0).findControl("TreeYearFrom"); 
        var treeTrademark = comboTm.get_items().getItem(0).findControl("TreeTrademark"); 
         
        setText(comboClass,treeClass,0); 
        setText(comboCountry,treeCountry,2); 
        setText(comboTm,treeTrademark,1); 
        setYear(comboYearFrom); 
        setYear(comboYearTo);      
    } 

However, I get the error in the load() function that all the comboboxes return 'null'.


1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 06 Apr 2009, 12:47 PM
Hello John Grymonprez,

Thank you for providing your code.

When the window.onload event handler executes the client-side objects are not yet initialized and this is the cause of the null RadComboBox objects.

A better approach would be to use the pageLoad function, which is called from the AJAX Framework once all client-side objects are initialized. In your case, just rename your load function to pageLoad to take advantage of the approach.

Regards,
Simon
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
John Grymonprez
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or