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

How to reload ComboBox on parent page?

12 Answers 588 Views
Window
This is a migrated thread and some comments may be shown as answers.
King Wilder
Top achievements
Rank 2
King Wilder asked on 14 Dec 2008, 12:10 AM
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

12 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Dec 2008, 10:46 AM
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.


0
Georgi Tunev
Telerik team
answered on 15 Dec 2008, 11:34 AM
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.
0
King Wilder
Top achievements
Rank 2
answered on 15 Dec 2008, 04:41 PM
Shinu,

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

King Wilder
0
King Wilder
Top achievements
Rank 2
answered on 15 Dec 2008, 04:44 PM
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
0
King Wilder
Top achievements
Rank 2
answered on 15 Dec 2008, 11:32 PM
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
0
Georgi Tunev
Telerik team
answered on 16 Dec 2008, 02:04 PM
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.
0
King Wilder
Top achievements
Rank 2
answered on 16 Dec 2008, 04:47 PM
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
0
Georgi Tunev
Telerik team
answered on 17 Dec 2008, 01:55 PM
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.
0
Stephen
Top achievements
Rank 2
answered on 22 Dec 2008, 11:49 AM

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

0
Georgi Tunev
Telerik team
answered on 22 Dec 2008, 01:34 PM
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.
0
jfkrueger
Top achievements
Rank 1
answered on 03 Apr 2009, 04:51 PM
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!
0
Sebastian
Telerik team
answered on 06 Apr 2009, 07:00 AM
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.
Tags
Window
Asked by
King Wilder
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Georgi Tunev
Telerik team
King Wilder
Top achievements
Rank 2
Stephen
Top achievements
Rank 2
jfkrueger
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or