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

[Solved] RadComboBox in User Control

13 Answers 767 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 02 Jul 2008, 02:21 PM
RE: 102 Telerik RadControls
Lab: External Streamer Pages


I followed the steps in the tutorial for moving the RadCombox into a user control but cannot get it to function. It works fine in the previous lab when the RadComboBox is on the aspx page directly.

A break point show me that the function RadComboBox1_ItemsRequested
in CountryStreamer.aspx never gets hit .

Am I missing something ?




public

partial class CountryStreamer : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void RadComboBox1_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)

{

DataTable dt = FetchMatchingCountries(e.Text);

RadComboBox combo = (RadComboBox)o;

combo.Items.Clear();

foreach (DataRow row in dt.Rows)

{

RadComboBoxItem item = new RadComboBoxItem(

row[

"Country"].ToString().ToLower());

item.Value = row[

"Code"].ToString();

combo.Items.Add(item);

}

}

private DataTable FetchMatchingCountries(string partialName)

{

string mdbPath = Server.MapPath("~/App_Data/Combobox.mdb");

OleDbConnection dbCon = new OleDbConnection(

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbPath);

dbCon.Open();

string sql = "SELECT * from CountryCodes WHERE Country LIKE '" +

partialName.Replace(

"'", "''") + "%'";

OleDbDataAdapter adapter = new OleDbDataAdapter(sql, dbCon);

DataTable dt = new DataTable();

adapter.Fill(dt);

dbCon.Close();

return dt;

}

}

----------------------------------------------------------

<%

@ Page Language="C#" AutoEventWireup="true" CodeFile="CountryStreamer.aspx.cs" Inherits="CountryStreamer" %>

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<

head runat="server"><title>Untitled Page</title></head>

<

body><form id="form1" runat="server"><div>

Start typing a Country Name:

<telerik:RadComboBox ID="RadComboBox1" runat="server"

AllowCustomText="True" EnableLoadOnDemand="True"

MarkFirstMatch="True" HighlightTemplatedItems="True"

ItemRequestTimeout="200" Width="150px"

OnClientItemsRequesting="RadComboBox1_ItemsRequested">

</telerik:RadComboBox></div></form></body></html>

-------------------------------------------------------------

public partial class CountryPicker : System.Web.UI.UserControl

{

protected void Page_Load(object sender, EventArgs e)

{

}

}

------------------------------------------------------

<%

@ Control Language="C#" AutoEventWireup="true" CodeFile="CountryPicker.ascx.cs" Inherits="CountryPicker" %>

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<telerik:RadComboBox ID="RadComboBox1" runat="server"

AllowCustomText="True" EnableLoadOnDemand="True" MarkFirstMatch="True"

Width="150px" ItemRequestTimeout="200" HighlightTemplatedItems="True"

ExternalCallBackPage="~/CountryStreamer.aspx">

</

telerik:RadComboBox>

-----------------------------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<%

@ Register TagPrefix="uc1" TagName="CountryPicker" Src="~/CountryPicker.ascx" %>

<

head runat="server"><title>Untitled Page</title></head>

<

body><form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>

<div>
<uc1:CountryPicker ID="cpPicker" runat="server" />
</
div></form></body></html>

 

13 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 02 Jul 2008, 03:02 PM
Hi Stephen,

Thank you for providing the code.

You need to subscribe to the OnItemsRequested event of the RadComboBox in the streamer page and not to the OnClientItemsRequesting event.

Please change that and everything should work fine.

Best wishes,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Stephen
Top achievements
Rank 1
answered on 02 Jul 2008, 05:17 PM
Hi Simon, I made that change but it the RadComboBox from the user control is still not populating the data.  I'm using VS2008. I've sent a zip of the simple web app to support@telerik.com.  Regards.
0
Simon
Telerik team
answered on 04 Jul 2008, 03:00 PM
Hello Stephen,

We have not received any e-mail from you.

Could you send us the project again referencing the forum thread please?

Best wishes,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Simon
Telerik team
answered on 07 Jul 2008, 01:29 PM
Hello Stephen,

Thank you for sending us the files.

Upon further examination of your code, I noticed that you are using the AJAX version of RadComboBox. With this version ExternalCallBackPages are not supported as they are not needed in case RadComboBox is located in a WebUserControl. The Load-On-Demand functionality in this situation works without any limitations - you can put the ItemsRequested event handler in the WebUserControl.

Please accept my apologies for not noticing this in the first place.

It also seems that you are using the Tutorial for the classic controls and many of the solutions there are inapplicable to RadControls for ASP.NET AJAX.

We are now working on the new version of the RadControls tutorial for
ASP.NET AJAX. It will be available in the coming weeks.

For now, please refer to the online documentation
(http://www.telerik.com/help/aspnet-ajax/ ), online demos
(http://www.telerik.com/demos) or forums (http://www.telerik.com/forums).

Finally, you can see a live example of the "Cascading Combos" approach and details on the implementation here.

All the best,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike
Top achievements
Rank 1
answered on 03 Dec 2008, 08:59 PM
Any update on this?  I am also using the Ajax controls from Telerik and their RadComboBox.  It really frustrates me that I have to put these comboBoxes in all of my code behind.  I want to utilize the user controls and the RadComboBox.
0
Atanas Korchev
Telerik team
answered on 04 Dec 2008, 03:47 PM
Hello Mike,

I am not sure what exactly you are asking. Why is using RadComboBox in codebehind frustrating to you? What do you mean by saying "I want to utilize the user controls and the RadComboBox"? RadComboBox can be used in user controls without any restrictions. What exactly are you trying to achieve with RadComboBox?


Kind regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike
Top achievements
Rank 1
answered on 04 Dec 2008, 04:00 PM
Albert,

Is there a WORKING example of using the ASP.NET AJAX RadComboBox as a user control?  I can put a regular textbox in the same page as the RadComboBox, and it works fine, but the RadComBoBox blows up with object not found.

My User control code
.....
<
telerik:RadComboBox ID="ComboBoxAssignedTo" Skin="Vista" runat="server" /> 
 
<asp:DropDownList AutoPostBack="false" ID="Category" runat="server">  
    <asp:ListItem Value="business">Business</asp:ListItem> 
    <asp:ListItem Value="trad_cook">Traditional Cooking</asp:ListItem> 
    <asp:ListItem Value="mod_cook">Modern Cooking</asp:ListItem> 
</asp:DropDownList> 

Code Behind.. no worky!
  protected void BindAssignedTo()  
    {  
        TeamListBLL teamList = new TeamListBLL();  
        RadComboBox RadComboBox1 = (RadComboBox)Page.Master.FindControl("Main").FindControl("RadComboBoxAssignedTo");  
        teamList.TeamId = 70847;  
        RadComboBox1.DataSource = teamList.GetTeamMembers;  
        RadComboBox1.DataTextField = "CONTACT_NAME";  
        RadComboBox1.DataValueField = "ID";  
        RadComboBox1.DataBind();  
    } 


Error:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 44:         RadComboBox RadComboBox1 = (RadComboBox)Page.Master.FindControl("Main").FindControl("RadComboBoxAssignedTo");
Line 45:         teamList.TeamId = 70847;
Line 46: RadComboBox1.DataSource = teamList.GetTeamMembers;Line 47:         RadComboBox1.DataTextField = "CONTACT_NAME";
Line 48:         RadComboBox1.DataValueField = "ID";

I have no idea why it can't find the Buisness Layer to populate the RadComboBox, the same code bound to a DropDownList does not error.
0
Atanas Korchev
Telerik team
answered on 04 Dec 2008, 04:04 PM
Hello Mike,

Most probably the FindControl chain returns null and your RadComboBox1 instance remains null. Please check whether all ID arguments passed to the FindControl method are correct.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike
Top achievements
Rank 1
answered on 04 Dec 2008, 04:07 PM
Why would it return a null, what is wrong with the code I posted?  Is there a demo of a user control using ASP.NET AJAX ComboBox, that actually works?
0
Atanas Korchev
Telerik team
answered on 04 Dec 2008, 04:15 PM
Hi Mike,

I am sending you a demo of RadComboBox in user control which works. As I said make sure that FindControl returns correct instance of RadComboBox as in my sample web site.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike
Top achievements
Rank 1
answered on 04 Dec 2008, 04:16 PM

Why is this in the code behind of the default.aspx and not the WebUserControl.ascx.cs?

 protected void Page_Load(object sender, EventArgs e)  
    {  
        if (!IsPostBack)  
        {  
            RadComboBox comboBox = (RadComboBox) Master.FindControl("WebUserControl1").FindControl("RadComboBox1");  
            comboBox.Items.Add(new RadComboBoxItem("Item 1"));  
            comboBox.Items.Add(new RadComboBoxItem("Item 2"));  
        }  
    } 

 
What's the point of code re-use if all you are doing is just replacing the radComboBox tag with a user control tag in the aspx page? 

I want the code listed above in the code behind of the User control, not the code behind of the aspx page.  That way if I have several of these I only need to change the code behind in ONE location.

0
Evgeni Belin
Top achievements
Rank 1
answered on 02 Sep 2009, 11:58 AM
Hi, I am ineterested in using radcombobox in usercontrol.  I want to declare linqdatasource in that usercontrol and have radcombobox bind to that linqdatasource, and itemtemplate bind to linqdatasource properties.

Is it possible?  If it is - what are the steps involved?  I tried many things but all fails.  On july 7 you said there will be new manuals coming out in "weeks".  It is sep 2nd now - is there an example of radcombobox in user control?

Thanks, -e 
0
Atanas Korchev
Telerik team
answered on 04 Sep 2009, 11:13 AM
Hi Evgeni Belin,

Binding RadListBox to LinqDataSource in usercontrol should be rather straightforward - the steps required are the same as if the controls are located in a normal page. I guess there is something else involved which is not mentioned here.

Regards,
Albert,
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
ComboBox
Asked by
Stephen
Top achievements
Rank 1
Answers by
Simon
Telerik team
Stephen
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Atanas Korchev
Telerik team
Evgeni Belin
Top achievements
Rank 1
Share this question
or