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
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
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
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
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.
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:
|
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.
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.
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.
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.
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,
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.