Simple question - ajax RCB rebind onclientclose

5 posts, 0 answers
  1. Garrett
    Garrett avatar
    35 posts
    Member since:
    Feb 2012

    Posted 23 Dec 2013 Link to this post

    Hi!

    I am trying to reload a radcombobox after a radwindow has closed using the onclientclose event.

    I have pieced together this code from google searches. It seems to want to work but doesn't quite hit the mark.

    My javascript:

               <script type="text/javascript">
     function UseRadWindow() {
                    var oWnd = $find("<%= RadWindow1.ClientID %>");
                    oWnd.show();
                    oWnd.minimize();
                    oWnd.maximize();
                    oWnd.restore();
                    oWnd.OnclientClose = "OCC";
                     
                }
                function OCC() {
                    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest();
    }

    My relevant aspx:

                <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" onajaxrequest="RadAjaxManager1_AjaxRequest">
          <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                <UpdatedControls>
                       <telerik:AjaxUpdatedControl ControlID="rcbCustomer" />
                </UpdatedControls>
                </telerik:AjaxSetting>
          </AjaxSettings>
    </telerik:RadAjaxManager>
      
     
             <telerik:RadWindowManager ID="RadWindowManager1" runat="server" style="z-index: 7001">
                    <Windows>
                        <telerik:RadWindow ID="RadWindow1" runat="server" NavigateUrl="addcust.aspx" Height="600px" Width="800px" Animation="Slide" OnClientClose="OCC">
                        </telerik:RadWindow>
                    </Windows>
                </telerik:RadWindowManager>
     
     
     <telerik:RadComboBox ID="rcbCustomer" Runat="server" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="ID" Skin="Default" EmptyMessage="Select Customer..." Filter="Contains" BorderColor="LightSteelBlue" BorderStyle="Dashed" BorderWidth="2px" Width="150px">
            <FooterTemplate>
               <telerik:RadButton ID="RadButton3" runat="server" OnClientClicked="UseRadWindow" Text="Add New..." AutoPostBack="False">
                   </telerik:RadButton>
            </FooterTemplate>
     </telerik:RadComboBox>


    And finally my only bit of cs:

    protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
    {
        //Bind the RadComboBod
        rcbCustomer.DataBind();
    }

    EDIT: I just enabled ENABLE LOADONDEMAND for the combobox but it did nothing.

    When I put a breakpoint on my ajaxrequest in the code behind, it DOES fire and does the DataBind() without issue, so I know that all the javascript is working. However the control does not rebind unless I refresh the page, which I do not want to do.
  2. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 26 Dec 2013 Link to this post

    Hello Garrett,

    Could you elaborate a bit more on your scenario? As I can see, you are attempting to show the RadWindow, in order to add new RadComboBoxItem. Do you insert the new item in the database, or you simply attempt to add it in the RadComboBox? If you are inserting the item in your database and then use the DataBind() method, once the window is closed, the RadComboBox will perform a request to its datasource and will rebind with the updated data. Please keep in mind that if you don't clear the current items in the RadComboBox and call DatBind(), the data will be duplicated. In addition, I am sending you the sample project, I have tested with - without inserting the newly added item in the database.

    Note : dll files are removed from the attachment.

    Regards,
    Nencho
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Garrett
    Garrett avatar
    35 posts
    Member since:
    Feb 2012

    Posted 26 Dec 2013 Link to this post

    Hi Nencho,


    Sorry I wasn't more clear, I should have explained the situation more.

    Here is the scenario:

    User is on CreateInvoice.aspx, where they are setting up an invoice. rcbCustomer is a database bound control that shows all the customers that we have. In the footer there is a create new customer button. If the user clicks that button, a new window will pop up. They will then insert information for the new customer (name, business name, blah blah) and click insert. The customer will then be inserted into the database.

    Here is where the problem begins.

    I have the radwindow working and the insert is working fine (it is on a separate button right now). 

    Once the user completes the insert, they click a CLOSE button in the radwindow that is bound Close() in this script:

    <script type="text/javascript">
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow)
                oWindow = window.radWindow;
            else if (window.frameElement.radWindow)
                oWindow = window.frameElement.radWindow;
            return oWindow;
        }
         
        function Close() {
            GetRadWindow().close();
        }
     
    </script>


    The radwindow has an OnClientClose that is set to this javascript:

    function OCC() {
        $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest();
    }

    So when the window closes, it's supposed to run the ajax request to update the radcombobox so that the new customer shows up in the list.

    Here is my ajax manager:

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

    It seems to want to work. It does call the "RadAjaxManager1_AjaxRequest" in code behind. I can tell because if I put a breakpoint inside of RadAjaxManager1_AjaxRequest it steps through like it should. However, the combo box does not update unless I refresh the entire page, which I do not want to do.

     
    I am bad at explaining things so if this is unclear at all please let me know.

    To sum it up, I have a combo box bound to a data source (sqldatasource) and I want to make it refresh so that it shows the most current set of data from that data source. I want to make this refresh happen when a radwindow closes.
  5. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 27 Dec 2013 Link to this post

    Hello Garrett,

    I understood the scenario you attempt to achieve. The approach you are currently using is the correct one and the RadComboBox should request its updated DataSource, once the DataBind() method is invoked. I would like to ask you to isolate the issue in a sample runnable project and submit a support ticket (along with the project attached), in order to inspect the faced issue locally and troubleshoot it for you.

    Regards,
    Nencho
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Garrett
    Garrett avatar
    35 posts
    Member since:
    Feb 2012

    Posted 27 Dec 2013 Link to this post

    Thank you Nencho, I am sending one now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017