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

[Solved] Related ComboBox FindControl

4 Answers 242 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 23 Aug 2009, 02:58 AM
I have a related combo box inside a form view insert item template that is returning the error message of "'regionsComboBox' is null or not an object".

I suspect that the issue is related to my use of the $find syntax of the 2nd combo box in the .aspx code, but cannot see it.

Can anyone see/help me with my error?

Here is my .aspx code:
     
    <script type="text/javascript"
        var regionsComboBox; 
         
        function pageLoad() { 
            regionsComboBox = $find('<%#((FormView)Container).FindControl("RadComboBox2").ClientID %>'); 
        } 
         
        function LoadRelatedRegions(combo, eventArqs) { 
            var item = eventArqs.get_item(); 
            regionsComboBox.set_text("Loading..."); 
 
            if (item.get_index() > 0) { 
                regionsComboBox.requestItems(item.get_value(), false); 
            } 
            else { 
                regionsComboBox.set_text(" "); 
                regionsComboBox.clearItems(); 
            } 
        } 
         
        function ItemsLoaded(combo, eventArqs) { 
            if (combo.get_items().get_count() > 0) { 
                combo.set_text(combo.get_items().getItem(0).get_text()); 
                combo.get_items().getItem(0).highlight(); 
            } 
            combo.hideDropDown(); //do not open region ddl when populated with regions. 
        } 
    </script> 
     
    <br /><br /> 
     
    <asp:ObjectDataSource ID="ObjectDataSource1"  
                                                OldValuesParameterFormatString="{0}"  
                                                runat="server"  
                                                SelectMethod="GetCountry"  
                                                TypeName="ResumeTableAdapters.ddlCountryTableAdapter"
        <SelectParameters> 
            <asp:ControlParameter ControlID="HiddenFieldGUID" Name="UserID" PropertyName="Value" Type="String" /> 
        </SelectParameters> 
    </asp:ObjectDataSource> 
     
    <asp:FormView ID="FormView1"  
                                runat="server"  
                                Caption="Related RadCombo inside a Form View Insert Item Template "  
                                BorderColor="Black"  
                                BorderWidth="1px"  
                                DefaultMode="Insert"  
                                Width="100%" > 
        <InsertItemTemplate> 
             
            <br /><br /> 
             
            <telerik:RadComboBox ID="RadComboBox1"  
                                                     AllowCustomText="false"  
                                                     DataSourceID="ObjectDataSource1"  
                                                     DataTextField="CountryShortNameIntl"  
                                                     DataValueField="CountryID"  
                                                     EnableLoadOnDemand="false"  
                                                     EnableTextSelection="true"  
                                                     EnableVirtualScrolling="true"  
                                                     Filter="StartsWith"  
                                                     Height="325px"  
                                                     HighlightTemplatedItems="true"  
                                                     MarkFirstMatch="true"  
                                                     MaxHeight="325"  
                                                     MaxLength="350"  
                                                     OnClientSelectedIndexChanged="LoadRelatedRegions"  
                                                     RadComboBoxImagePosition="<%$ Resources:Resource, Direction %>"  
                                                     Runat="server"  
                                                     Skin="Black"  
                                                     Width="55%"
                <ItemTemplate> 
                    <div style="padding: 2px;"
                        <asp:Image ID="ImageInsertCountryFlagIconPath" ImageAlign="AbsMiddle" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "CountryFlagIconPath") %>' Runat="server" SkinID="flag" /> 
                        <asp:Label ID="LabelInsertCountryShortNameIntl" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CountryShortNameIntl") %>' CssClass="genMed" /> 
                    </div> 
                </ItemTemplate> 
            </telerik:RadComboBox> 
             
            <br /><br /> 
             
            <telerik:RadComboBox ID="RadComboBox2"  
                                                     AllowCustomText="false"  
                                                     EnableTextSelection="true"  
                                                     EnableVirtualScrolling="true"  
                                                     ErrorMessage="StartsWith"  
                                                     HighlightTemplatedItems="true"  
                                                     LoadingMessage="Load Moi"  
                                                     MarkFirstMatch="true"  
                                                     OnClientItemsRequested="ItemsLoaded"  
                                                     OnItemsRequested="RadComboBox2_ItemsRequested"  
                                                     RadComboBoxImagePosition="<%$ Resources:Resource, Direction %>"  
                                                     Runat="server"  
                                                     Skin="Black"  
                                                     Width="50%" /> 
             
            <br /><br /> 
             
        </InsertItemTemplate> 
         
    </asp:FormView> 
     

Here is my .cs code:
    protected void Page_Load(object sender, EventArgs e) 
    { 
 
    } 
 
    protected void LoadRelatedRegions(string countryID) 
    { 
        ddlRegionTableAdapter regionsTableAdapter = new ddlRegionTableAdapter(); //create regionsTableAdapter. 
 
        RadComboBox RadComboBox2 = (RadComboBox)FormView1.FindControl("RadComboBox2"); 
        RadComboBox2.DataSource = regionsTableAdapter.GetRegion(GetGuid(), Convert.ToInt32(countryID)); //assign the rad combo box datasource to the regionsTableAdapter. 
        RadComboBox2.DataTextField = "RegionNameIntl"//assign the data text field. 
        RadComboBox2.DataValueField = "RegionID"//assign the data value field. 
        RadComboBox2.DataBind(); //data bind the rad combo box. 
    } 
 
    protected void RadComboBox2_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) 
    { 
        // e.Text is the first parameter of the requestItems method  
        // invoked in LoadRegions method  
        LoadRelatedRegions(e.Text); 
    } 
 
    protected Guid GetGuid() 
    { 
        Guid uid = new Guid(Membership.GetUser().ProviderUserKey.ToString()); //assign the users guid (userid) to the uid parameter using Guid.  
        return uid; //return the value;  
    } 
 


4 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 23 Aug 2009, 03:54 AM

0
Matt
Top achievements
Rank 1
answered on 25 Aug 2009, 11:11 PM
The related combox is populated when it is ouside the FormView InsertItemTemplate, but retuens the error when it is placed insed the FormView control.

I have tried different scenarios to find the related rad combo box in JS, but all attempts fail

Any suggestions?
0
Matt
Top achievements
Rank 1
answered on 28 Aug 2009, 09:12 AM
How can I find the related combo box inside the form view insert item template if the form view has not been created when the page loads?

If any one could offer some advice to solve this issue, it would be greatly appreciated.
0
Matt
Top achievements
Rank 1
answered on 04 Sep 2009, 03:07 AM
Can anyone give me an answer?
Tags
ComboBox
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Share this question
or