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:
Here is my .cs code:
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; |
| } |