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

Load RadGrid using ajax request

1 Answer 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrei
Top achievements
Rank 1
Andrei asked on 19 Feb 2011, 12:10 PM
Hello,

I have a custom ascx controls contains RadGrid and RadChart.

The control is loaded into ajax panel using ajax request
protected void RadAjaxPanel2_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
if (e.Argument == "InitialLoad")
{
var auctionTotals = LoadControl("~/core/Informers/CurrencyRates.ascx");
auctionTotals.ID = "CurrencyRates";
panel2.Controls.Add(auctionTotals);
}
}
Inside the user control every grid row has a related chart dislayed when this row is selected.
function <%=ClientID%>_grid_OnRowSelected(sender, args) {
<%=ClientID%>_selectChart(parseInt(args._itemIndexHierarchical));
}

Here is how the event handler is added

var events = grid.ClientSettings.ClientEvents;
events.OnRowSelected = ClientID + "_grid_OnRowSelected";

Everything works just fne if the control is used on the aspx page (like a normal aspx control). But as soon as I try to load this control dynamically using ajax panel (using the first code snapshot), I get a javascript error: content_CurrencyRates_grid_OnRowSelected is not defined

I am a bit confused why the event handler is not binded to the grid in this scenario. Should this function be placed in some other part of the ascx control?

Thanks,
Andrei

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 24 Feb 2011, 12:54 PM
Hi Andrei,

You need to wrap the script for the OnRowSelected handler into RadScriptBlock. This is required because dynamically loaded scripts need to be registered through the ScriptManager in order to work properly.

<telerik:RadScriptBlock runat="server">
  <script type="text/javascript" language="javascript">
    function <%=ClientID%>_grid_OnRowSelected(sender, args) {
     <%=ClientID%>_selectChart(parseInt(args._itemIndexHierarchical));
    }
  </script>
</telerik:RadScriptBlock>

Also if you want this dynamically loaded user control to be loaded after the next postback you have to reload it in Page_Load or in Page_Init. See this help topic for more information:
http://www.telerik.com/help/aspnet-ajax/ajxloadusercontrols.html

Greetings,
Vasil
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Andrei
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or