How to reload ComboBox on parent page?

13 posts, 0 answers
  1. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 13 Dec 2008 Link to this post

    On my parent page (aspx) I have a RadComboBox control with a list of client names.  Next to it I have a link that called "Manage" that opens a RadWindow.

    In the RadWindow is a RadGrid where the user can Add/Edit/Delete client names that update the database.

    What I'm trying to do is, when the user adds a new client in the RadWindow (which adds it to the database), and he closes the RadWindow, I want the RadComboBox on the parent page to be reloaded automatically with the new data.

    Is this possible either via client-side or server-side?

    Thanks,

    K Wilder
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Dec 2008 Link to this post

    Hi King Wilder.

    One suggestion is that add RadAjaxManager on page and call the AjaxRequest to bind the RadComboBox on clossing the RadWindow. In order to perform that, add "OnClientClose" event for RadWindow, and then call the AjaxRequest. At the server side you can bind the RadComboBox from the "RadAjaxManager1_AjaxRequest" method. Please try the following code snippets.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox1" Runat="server"
         <Items> 
            <telerik:RadComboBoxItem Text="Item1" Value="Value1"/> 
         </Items> 
    </telerik:RadComboBox> 
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
     
    <asp:Button ID="Button1" runat="server" Text="Button" /> 
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server"
         <Windows> 
             <telerik:RadWindow runat="server" Behavior="Default" InitialBehavior="None" Left="" NavigateUrl="window.aspx" OpenerElementID="Button1" style="display: none;" Top="" OnClientClose="ClientClose"
             </telerik:RadWindow> 
         </Windows> 
    </telerik:RadWindowManager>     
             
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" onajaxrequest="RadAjaxManager1_AjaxRequest"
          <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"
                <UpdatedControls> 
                       <telerik:AjaxUpdatedControl ControlID="RadComboBox1" /> 
                </UpdatedControls> 
                </telerik:AjaxSetting> 
          </AjaxSettings> 
    </telerik:RadAjaxManager> 

    JavaScript:
    <script type="text/javascript"
    function ClientClose() 
        $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest(); 
    </script> 

    CS:
    protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e) 
         //Bind the RadComboBod 
         RadComboBox1.DataBind(); 

    Thanks,
    Shinu.


  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 15 Dec 2008 Link to this post

    Hi King,

    You can do this by using the OnClientClose eventhandler of RadWindow that specifies the name of the client function to be executed when a RadWindow is closed.

    As for updating the combobox, RadComboBox does not have internal rebind / refresh so when you receive the argument on the page, you should either update your database and call DataBind() for the combobox or as an alternative - add the new item to the already loaded ones.
    More information on the subject is available in the documentation and in the following demos:
    http://www.telerik.com/demos/aspnet/prometheus/ComboBox/Examples/Programming/AddRemoveDisableItemsClientSide/DefaultCS.aspx
    http://www.telerik.com/demos/aspnet/prometheus/ComboBox/Examples/Programming/AddRemoveDisable/DefaultCS.aspx

    I hope this helps.


    All the best,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 15 Dec 2008 Link to this post

    Shinu,

    Thanks for the suggestion.  I will give it a try.

    King Wilder
  6. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 15 Dec 2008 Link to this post

    Georgi,

    I will look closer at your suggestions and give it a try.  If I come up with a somewhat solid example I will post it to the Code Library.

    Thanks,

    King Wilder
  7. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 15 Dec 2008 Link to this post

    Ok, I almost got it, but the combo box is not refreshing.

    In the parent page that launches the RadWindow, it also contains the RadComboBox control that should be reloaded when the RadWindow closes, and it isn't.  The following code in the Default.aspx page is being executed, but the RadComboBox control doesn't reflect the reload.

        private void LoadCombo() 
        { 
            ClientsDb clients = new ClientsDb(); 
            ddlClients.DataSource = clients.GetAllClients(); 
            ddlClients.DataTextField = "Company"
            ddlClients.DataValueField = "ClientID"
            ddlClients.DataBind(); 
        } 
     
        protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e) 
        { 
            LoadCombo(); 
        } 


    I have a small web site project that has everything as I need it in my project.  I tried some suggestions from Shinu and almost got there.  You can download it from http://www.kingwilder.com/RadWindowToRadComboBoxSample.zip.  (You'll need to add your own Telerik DLL)

    If someone can look over the code and see what I'm missing, I would appreciate it.

    Thanks,

    King Wilder
  8. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 16 Dec 2008 Link to this post

    Hi King,

    When calling Ajax request from JavaScript you must set the RadAjaxManager to update the corresponding control  - the ID that you have set is the id of a standard HTML link - it will not work this way.

    Try setting it up like this:

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="ddlClients" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 




    Sincerely yours,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. King Wilder
    King Wilder avatar
    240 posts
    Member since:
    Oct 2007

    Posted 16 Dec 2008 Link to this post

    Thank you, that worked! 

    The reason I put the HTML link there is that I thought it would be the initiating control for the ajax request, not the RadAjaxManager itself.

    Do you mind if I put this up in the Code Library?  I'm sure it will come in handy.

    Thanks,

    King Wilder
  10. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 17 Dec 2008 Link to this post

    Hi King,

    Of course we don't mind :) I am sure that others will benefit from your article. Here are some suggestions for the code library article:
    1. Make sure that the project that you will post there can be run locally - e.g. is not missing database, controls, etc.
    2. Remove the Telerik's dll files before uploading it or use trial ones.
    3. It will be best if you use comments in your code that explain what exactly will happen - this will help the others to understand your logic better. 

    I hope this helps.

    Sincerely yours,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  11. Stephen
    Stephen avatar
    40 posts
    Member since:
    Jul 2008

    Posted 22 Dec 2008 Link to this post

    Yes very helpful posts.

    I'm having problems still mainly because i'm using a RadAjaxManagerProxy instead of a RadAjaxManager. I have my popup all happening on a webcontrol so its making things a little more complicated.

    How do I refresh a gridview on the parent page after the popup radwindow is closed? I think i've got everything except the missing Ajax event. The proxy doesnt seem to have the event.

     

    thanks,

    Stephen Price

  12. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 22 Dec 2008 Link to this post

    Hello King,

    Have you checked the "RadAjax and WebUserControls" article in the documentation? I believe that it will be of help - here is a direct link to the online version:
    http://www.telerik.com/help/aspnet-ajax/ajxusercontrols.html



    Greetings,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  13. jfkrueger
    jfkrueger avatar
    269 posts
    Member since:
    Jul 2012

    Posted 03 Apr 2009 Link to this post

    How would you do this when the ComboBox is inside the Edit/Insert form of a grid? I have tried to iterate through all items in the grid in the RadAjaxManager1_AjaxRequest method but at the time it fires there is always only 1 item in the grid.

    Thanks!
  14. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 06 Apr 2009 Link to this post

    Hello Joe,

    Based on the context, you can refresh the controls in the same grid row or the entire grid instance from a popup window as demonstrated in the following online demos of the product:

    http://demos.telerik.com/aspnet-ajax/grid/examples/programming/accessingcellsandrows/defaultcs.aspx

    http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=grid

    Review the information/code snippets from them and modify/extend the solutions accordingly to be in par with your custom configuration schema.

    Kind regards,
    Sebastian
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017