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

Radgrid not rebinding in c# codebehind

6 Answers 450 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 06 Nov 2008, 04:00 AM
I have written about  this subject before, but I have found a hack on how to call the c# code behind from javascript and when I do that, and call rebind from the c#, the grid is not rebinding. Here is what I am doing:

I have a grid and button outside the grid which creates a modal radwindow to generate a wizard to create users. When the wizard completes and the window closes, I have a javascript function to handle the window close and in that function, I have one line which clicks a hidden button so that the onclick server call for that button can get called automatically. The call gets called, and in that call all I have is a rebind. It runs according to my debugger, but the grid does not refresh. The users do get generated becasue if I then click the refresh button the grid refreshes.

 I have a radajaxmanager set up so that the button controls the grid.(the hidden button is called myServerButton. here is my code:

 <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1" >
       <ClientEvents OnRequestStart="centerUpdatePanel();"></ClientEvents>
       
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="myServerButton">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="usersGrid" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="WizardButton">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="CompanyInfoGrid" />
                            <telerik:AjaxUpdatedControl ControlID="usersGrid" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="TopGrid">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="TopGrid" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="CompanyInfoGrid">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="CompanyInfoGrid" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="usersGrid">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="TextBoxOrderDetailID" />
                            <telerik:AjaxUpdatedControl ControlID="CompanyInfoGrid" />
                            <telerik:AjaxUpdatedControl ControlID="usersGrid" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
    </telerik:RadAjaxManager>

.........  
<asp:Button ID="myServerButton" runat="server" style="display:none;"  OnClick="rebindUsers"  />

  <telerik:RadGrid ID="usersGrid" runat="server"
       DataSourceID="ContentCentralUsers" GridLines="None" Skin="Office2007" AutoGenerateColumns="False"
            ondatabound="usersGrid_DataBound" onitemdatabound="usersGrid_ItemDataBound"   OnItemCreated="usersGrid_ItemCreated"
            onitemevent="usersGrid_ItemDataBound" oniteminserted="usersGrid_ItemInserted" onitemupdated="usersGrid_ItemUpdated"
            ShowStatusBar="True" OnPreRender="usersGrid_PreRender" oninsertcommand="usersGrid_InsertCommand" OnItemCommand="usersGrid_ItemCommand"
            onupdatecommand="usersGrid_UpdateCommand"   >
     
       <MasterTableView  DataSourceID="ContentCentralUsers"  DataKeyNames="user_id,package_cd"
             AllowFilteringByColumn="True" AllowSorting="True"   
              InsertItemPageIndexAction="ShowItemOnFirstPage" CommandItemDisplay="Top"
             NoMasterRecordsText="No users to display.">
            <CommandItemSettings AddNewRecordText="Add new user"  />
            
            <RowIndicatorColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
   
            <ExpandCollapseColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            
   
     <Columns>
.....
<script type="text/javascript">

 function OnClientClose(oWnd) {
        document.getElementById('myServerButton').click(); // clicks hidden button to invoke c# call to rebind users
    }

 function openWin(OrderDetailID) {

        var urlArgs = cbeGetURLArguments();

        var sbOID = parseInt(urlArgs['sbOID']);
        var queryODID = parseInt(urlArgs['sbODID']);
        var sbproductid = parseInt(urlArgs['sbproductid']);
        var SAPID = urlArgs['SAPID'];

        var txtbxODID = document.getElementById('TextBoxOrderDetailID').value;
        var txtbxProduct = document.getElementById('TextBoxProduct').value;
        var licensePrice = document.getElementById('licensePrice').value;
        if (txtbxODID == null)
            sbODID = queryODID;
        else
            sbODID = txtbxODID;


        var windowURL = "v8Wizard_1.aspx?sbODID=" + sbODID + "&sbproductid=" + sbproductid + "&SAPID=" + SAPID +
                 "&lPrice=" + licensePrice + "&email=" + "" + "&ttt=" + "" + "&p_cd=" + "NTB" + "&sbOID=" + sbOID + "&numUsers=&packagePrice=0";

        var oWnd = radopen(windowURL, "RadWindow1");
        oWnd.setSize(900, 550);
        // oWnd.setSize(650, 600);
        oWnd.center();

        //set a function to be called when RadWindow is closed
        oWnd.add_close(OnClientClose);
    }
   
   </script>
......

  protected void rebindUsers(Object sender, EventArgs e)
    {
        usersGrid.Rebind();
       
    }
    
The rebind gets executed, but the grid does not refresh.







6 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 07 Nov 2008, 02:43 PM
Hello Laura,

Can you check if the grid is updated if the button is visible?

Additionally, I suggest that you update your grid invoking ajax request instead. Then you can handle the grid rebind in the RadAjaxManager AjaxRequest server event:

<script type="text/javascript">  
function OnClientClose(oWnd)   
{  
    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindOnClose");  
}  
</script>  
 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" 
    OnAjaxRequest="RadAjaxManager1_AjaxRequest">     
    <AjaxSettings>    
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">     
            <UpdatedControls>    
                <telerik:AjaxUpdatedControl ControlID="usersGrid" />    
            </UpdatedControls>    
        </telerik:AjaxSetting>    
    </AjaxSettings>    
</telerik:RadAjaxManager>    
 
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)  
{  
    if(e.Argument == "RebindOnClose")  
    {  
        usersGrid.Rebind();  
    }  

Give it a try and let me know if it helps.

Kind regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Laura
Top achievements
Rank 1
answered on 07 Nov 2008, 02:50 PM
Thank you for the reply. After writing to you, I did change it to rebind on an Ajax request and it still did not rebind. I found out the problem though. In the radwindow code, I had a button click to save the grid. On the button click, there was a client handler and a server handler. The client handler was executing first, closing the window and the rebind was called, and then finally, the server handler was being called to save the grid. So the rebind was happening before the data was saved to the database. I fixed it by calling the javascript from inside the c# after the save and now all is good.

Thanks
0
Raja M
Top achievements
Rank 1
answered on 28 Feb 2012, 10:23 AM
Hi Laura,

I am also facing the same issue.
Could you please explain how to call the javascript method using code behind in c#.
I was tried by this way:
ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);

But it won't work and also the OnAjaxRequest also not fired.

Could you please help me on this


Regards,
Raja M
0
Maria Ilieva
Telerik team
answered on 01 Mar 2012, 06:11 PM
Hello Raja,

See the following help topic for more information on this matter:

http://www.telerik.com/help/aspnet-ajax/ajax-execute-custom-javascript.html

I hope this helps.

All the best,
Maria Ilieva
the Telerik team
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 their blog feed now.
0
Rohan
Top achievements
Rank 1
answered on 06 Dec 2012, 01:52 PM
Hi Maria,

I have one user control with rad grid . One page contains more that two instance of same user control i want to create selected changed event of one user control's rad grid update the remaining user control radgrid according the selected record .....
I am able to do this ... but my problem is i am not able to update other user control rad grid with new data source .... i need to click on refresh button of rad grid to get new data. is there any way to update new data source of rad grid ...

for update the rad grid of user control i try this code
 ScriptManager.RegisterStartupScript(this.Page, GetType(), key, "RefreshGridRebind('" + _grdDataListView.ClientID + "','" + count + "');", true);
and my javascript function

 function RefreshGridRebind(X) {

       var masterTable = $find(X).get_masterTableView();
        masterTable.rebind();
    
   }

using this code i am able to update only last instance of user control rad grid with new data source.....
please provide any example or document .....

Thanks  

0
Maria Ilieva
Telerik team
answered on 11 Dec 2012, 12:58 PM
Hello Rohan,

In the RefreshGridRebind function you could invoke a manual ajaxRequest|() and then on the server OnAjaxRequest event call Rebind for all the RadGrid controls in the UserControls.

Regards,
Maria Ilieva
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Laura
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Laura
Top achievements
Rank 1
Raja M
Top achievements
Rank 1
Maria Ilieva
Telerik team
Rohan
Top achievements
Rank 1
Share this question
or