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.
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.