ASP List-view inside a User-control. How to fire a javascript after the User-control has fully loaded?

StackOverflow https://stackoverflow.com/questions/11902996

سؤال

I am using 2 Usercontrols:

  • Search.ascx
  • Results.ascx

They are ajaxfied using Telerik in that Search updates the Results control.

My actual problem is i want to implement DataTables for the generated table inside the Results control.

How can i call the datatables jquery function after the table has been (re)-generated ?

I use the following markup in my aspx page. If i click on search within the search usercontrol the results get displayed via the Results control. Note that the results usercontrol gets divved/ajaxfied using telerik.

<telerik:radscriptmanager runat="server" id="RadScriptManager" />
<telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="UcSearch">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="UcResults" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<uc1:ucSearch runat="server" id="UcSearch"></uc1:ucSearch>
<uc1:ucResults runat="server" id="UcResults"></uc1:ucResults>
هل كانت مفيدة؟

المحلول

The problem is that we can't use RadAjaxManager's OnResponseEnd client event as it not raised when you ajaxifying user controls. Here is an link from Telerik's forum: ajax panel ClientEvents-OnRequestStart wont fire. But you can enforce RadAjaxManager to call some client-side script after response returned to client: ResponseScripts Property. So all that you need it's to place another JavaScript function onto the page to apply DataTables plugin if you don't have one yet and instruct the RadAjaxManager to call this function after refreshing Results control.

void UcSearch_DoSearch(object sender, EventArgs e)
{
    // your code to update UcResults control 

    RadAjaxManager1.ResponseScripts.Add("initDataTable();");
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top