I have a RadCombobox on an ASP.net page with VB.net code-behind. There is a RadButton near the RadCombobox that is set up to update the RadCombobox with values from a database table. When clicking on the RadButton, a query is executed which returns a Dataset of the results and the dataset is used to populate an Array List and the Array List is used as the Data Source for the RadCombobox and then DataBind for RadCombobox is called.
I am using the Array List as the Data Source for the RadCombobox because "ALL" needs to be the first item in the RadCombobox.
I would like to be able to use the RadAjaxLoadingPanel on the RadCombobox and RadButton because the update will take a few minutes and need something to show the user that the update process is running. With the RadAjaxLoadingPanel used on the RadButton, it prevents the user from clicking on the RadButton again while the update process is running.
The problem that I am having when using the RadAjaxLoadingPanel is that after the update has completed that the RadCombobox is showing any new values. I have to refresh the page to get it to show new values.
Please help me to get this to work with the RadAjaxLoadingPanel. Thanks!
Here is how the AjaxManager is setup:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnablePageHeadUpdate="False"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="rcbbSupplierCode" LoadingPanelID="comboboxLoadingPanel"></telerik:AjaxUpdatedControl> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="rbtnUpdateSuppCodes"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="rbtnUpdateSuppCodes" LoadingPanelID="buttonLoadingPanel"/> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings></telerik:RadAjaxManager>
Here is the code for the RadCombobox, RadButton and the Loading Panels:
<telerik:RadAjaxLoadingPanel runat="server" ID="comboboxLoadingPanel"></telerik:RadAjaxLoadingPanel><telerik:RadComboBox ID="rcbbSupplierCode" runat="server" MaxHeight="350px" OnClientLoad="textBoxLoadValidCharsOnly" Width="240px" AutoPostBack="true" RenderMode="Lightweight" Filter="StartsWith" MarkFirstMatch="True" EnableTextSelection="true" AllowCustomText="false" onpaste="return false"/><telerik:RadAjaxLoadingPanel runat="server" ID="buttonLoadingPanel"></telerik:RadAjaxLoadingPanel><telerik:RadButton ID="rbtnUpdateSuppCodes" runat="server" Text="Update Supplier Codes" RenderMode="Lightweight"></telerik:RadButton>
Sincerely,
Keith Jackson
11 Answers, 1 is accepted
Hi Keith,
I think you forgot to add a reference of your ComboBox in your "UpdatedControls" of your Button :
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnablePageHeadUpdate="False"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="rcbbSupplierCode" LoadingPanelID="comboboxLoadingPanel"></telerik:AjaxUpdatedControl> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="rbtnUpdateSuppCodes"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="rcbbSupplierCode" LoadingPanelID="comboboxLoadingPanel"/> <telerik:AjaxUpdatedControl ControlID="rbtnUpdateSuppCodes" LoadingPanelID="buttonLoadingPanel"/> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings></telerik:RadAjaxManager>Thanks Loic! But that did not work. The new values will not show unless I refresh the page.
I still need help with this.
Sincerely,
Keith Jackson
Hi Keith,
Well, are you sure to call your "UpdateSuppCodes" method on your button click event ? And not only in your PageLoad method ?
Hi Loic,
On button click, rbtnUpdateSuppCodes_Click is called.
If you can provide a working example then that would be helpful.
Sincerely,
Keith Jackson
Here is a very simple example that shows how you can update RadComboBox without refresh the page.
ASPX :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title></head><body> <form id="form1" runat="server"> <telerik:RadScriptManager runat="server"></telerik:RadScriptManager> <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" Skin="Bootstrap"></telerik:RadAjaxLoadingPanel> <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" UpdatePanelsRenderMode="Inline"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="rbtnUpdateSuppCodes"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="rcbbSupplierCode" LoadingPanelID="RadAjaxLoadingPanel1" /> <telerik:AjaxUpdatedControl ControlID="rbtnUpdateSuppCodes" LoadingPanelID="RadAjaxLoadingPanel1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <div> <telerik:RadButton ID="rbtnUpdateSuppCodes" runat="server" Text="Update Supplier Codes" OnClick="rbtnUpdateSuppCodes_Click"></telerik:RadButton> <telerik:RadComboBox ID="rcbbSupplierCode" runat="server"></telerik:RadComboBox> </div> </form></body></html>
C# :
using System;using System.Web.UI;public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { rcbbSupplierCode.Items.Add("No items"); } } protected void rbtnUpdateSuppCodes_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(5000); rcbbSupplierCode.Items.Clear(); for (int i = 1; i <= 10; i++) { rcbbSupplierCode.Items.Add("Item " + i.ToString("00")); } }}
Let me know if you have any other questions.
Hi Loic,
Thanks for providing the simple example!
It does work as is and works when I change the rbtnUpdateSuppCodes_Click to bind the DataSource of rcbbSupplierCode to an ArrayList.
But it does not work when I pass rcbbSupplierCode by reference to a function in a .vb file in App_Code folder.
Here is a copy of rbtnUpdateSuppCodes_Click :
Protected Sub rbtnUpdateSuppCodes_Click(sender As Object, e As EventArgs) Dim ComboboxList As New ArrayList() Dim strFilename As String = "", strFieldName As String = "" Dim sql As String = "" System.Threading.Thread.Sleep(5000) rcbbSupplierCode.Items.Clear() ComboboxList.Add("ALL") For i As Integer = 1 To 100 'rcbbSupplierCode.Items.Add("Item " + i.ToString("00")) ComboboxList.Add("Item " + i.ToString("00")) Next 'rcbbSupplierCode.DataSource = ComboboxList 'rcbbSupplierCode.DataBind() strFilename = "RSDCContainerScrapppedSuppCodes.txt" sql = "SELECT DISTINCT SUPPLIER_CODE FROM VIEW_PLEX_CONT_SCRAPPED_RPT WHERE NOT SUPPLIER_CODE IS NULL ORDER BY SUPPLIER_CODE ASC" strFieldName = "SUPPLIER_CODE" rcbbSupplierCode.DataSource = Nothing UserFunctions.UpdateRadCombobox(strFilename, sql, strFieldName, rcbbSupplierCode, "S01", True)End Sub
Here is the code for UpdateRadCombobox procedure in the .vb file in App_Code folder:
Public Shared Sub UpdateRadCombobox(ByVal sFile As String, ByVal sSQL As String, ByVal sTableField As String, ByRef RadComboboxObj1 As RadComboBox, ByVal sDBServer As String, Optional ByVal bAddALL As Boolean = False) Dim dsList As DataSet Dim strFilePath As String Dim SWFileWrite As System.IO.StreamWriter Dim ComboboxList As New ArrayList() dsList = DataSetConfiguration.OracleDataSet(sSQL, sDBServer) If RadComboboxObj1.Items.Count > 0 Then RadComboboxObj1.Items.Clear() End If If bAddALL Then ComboboxList.Add("ALL") End If If dsList.Tables(0).Rows.Count > 0 Then strFilePath = HttpContext.Current.Server.MapPath(sFile) If File.Exists(strFilePath) Then SWFileWrite = File.CreateText(strFilePath) For Each iRow In dsList.Tables(0).Rows SWFileWrite.WriteLine(iRow(sTableField)) ComboboxList.Add(iRow(sTableField)) Next SWFileWrite.Close() End If End If RadComboboxObj1.DataSource = ComboboxList RadComboboxObj1.DataBind()End Sub
Any ideas?
Sincerely,
Keith Jackson
Hi Keith,
I've tried to reproduce the same configuration, but unfortunately it works for me when I pass rcbbSupplierCode by reference to a function in a .cs file in App_Code folder. The only difference is I'm using C#.
Are you sure of your "If dsList.Tables(0).Rows.Count > 0 Then" Condition ? Or of your "For loop" ?
Can you try this ? rbtnUpdateSuppCodes_Click :
Protected Sub rbtnUpdateSuppCodes_Click(sender As Object, e As EventArgs) UserFunctions.UpdateRadCombobox("", "", "", rcbbSupplierCode, "S01", True) End Sub
UpdateRadCombobox procedure in the .vb file in App_Code folder :
Public Shared Sub UpdateRadCombobox(ByVal sFile As String, ByVal sSQL As String, ByVal sTableField As String, ByRef RadComboboxObj1 As RadComboBox, ByVal sDBServer As String, Optional ByVal bAddALL As Boolean = False) Dim ComboboxList As New ArrayList() System.Threading.Thread.Sleep(5000) RadComboboxObj1.Items.Clear() ComboboxList.Add("ALL") For i As Integer = 1 To 100 ComboboxList.Add("Item " + i.ToString("00")) Next RadComboboxObj1.DataSource = ComboboxList RadComboboxObj1.DataBind() End SubHi Loic,
I have tried what you suggested with your example page and it worked.
I did some additional testing to narrow down when the problem occurs. I have found that the problem occurs when populating a Dataset from a database table even though the dataset is not binded to the RadCombobox.
UpdateRadCombobox procedure in the .vb file in App_Code folder with additional changes:
Public Shared Sub UpdateRadCombobox(ByVal sFile As String, ByVal sSQL As String, ByVal sTableField As String, ByRef RadComboboxObj1 As RadComboBox, ByVal sDBServer As String, Optional ByVal bAddALL As Boolean = False) Const S01CONNECTIONSTRING As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.0.1.11)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=S01)));User Id=User;Password=GPwd;" Dim dsList As New DataSet 'Dim strFilePath As String 'Dim SWFileWrite As System.IO.StreamWriter Dim ComboboxList As New ArrayList() Dim OrConn As Oracle.DataAccess.Client.OracleConnection OrConn = New Oracle.DataAccess.Client.OracleConnection(S01CONNECTIONSTRING) Dim OrCmd As Oracle.DataAccess.Client.OracleCommand = New Oracle.DataAccess.Client.OracleCommand(sSQL, OrConn) OrCmd.CommandType = CommandType.Text Dim OrDa As Oracle.DataAccess.Client.OracleDataAdapter = New Oracle.DataAccess.Client.OracleDataAdapter(OrCmd) Dim OrCB As Oracle.DataAccess.Client.OracleCommandBuilder = New Oracle.DataAccess.Client.OracleCommandBuilder(OrDa) OrDa.Fill(dsList) 'System.Threading.Thread.Sleep(5000) RadComboboxObj1.Items.Clear() ComboboxList.Add("ALL") For i As Integer = 1 To 100 ComboboxList.Add("Item " + i.ToString("00")) Next RadComboboxObj1.DataSource = ComboboxList RadComboboxObj1.DataBind()End Sub
Any ideas?
Sincerely,
Keith Jackson
Hi Keith,
Unfortunately, I have no idea why... Maybe you could try a different approach.
What if your "UpdateRadCombobox" method return a Dataset object and then you bind your RadCombobox in your "rbtnUpdateSuppCodes_Click" method with the result of this Dataset ?
Hi Loic,
I would bind the Dataset object to the RadCombobox but I need "ALL" to be the first item.
I have tried setting up "UpdateRadCombobox" method to return an ArrayList and then bind the RadCombobox to the ArrayList but still had the same problem.
I guess I will have to open a support ticket with Telerik.
Thanks for your help!
Sincerely,
Keith Jackson
Telerik support helped me to resolve this issue.
The issue was caused by a server request timeout occurring. By default, the script manager timeout is 90 seconds. Since the query to the database takes longer than 90 seconds to come back, the timeout occurs.
Since the query takes about 2 minutes to get the results, needed to add AsyncPostBackTimeout="180" to the script manager.
Then I put the RadCombobox and RadButton in an UpdatePanel. Because I am using the RadAjaxLoadingPanel for the RadCombobox and RadButton, there is no need to call the Update method of the UpdatePanel. In fact calling the Update method of the UpdatePanel causes something else to be displayed on the page that should not be displayed. I have tested this in Internet Explorer, Chrome, and Firefox on a Windows 7 system and works without any problems.
Sincerely,
Keith Jackson