简体   繁体   English

在ASP.NET中更新Ajax后加载Jquery

[英]Load Jquery after async ajax update in asp.net

I have a ASP.net page that is jquery heavy. 我有一个jquery重的ASP.net页面。

on this page I have a gridview inside a updatepanel so I can make a asynch update. 在此页面上,我在updatepanel中有一个gridview,因此可以进行异步更新。

<asp:GridView ID="gvMail" runat="server" GridLines="None" 
AutoGenerateColumns="false" Width="100%" OnRowDataBound="mail_RowDataBound"
CssClass="gridview" DataKeyNames="id">


<HeaderStyle HorizontalAlign="Left" />
<RowStyle ForeColor="#0072BC" HorizontalAlign="Left" CssClass="draggable" />

</asp:GridView>

</ContentTemplate>
</asp:UpdatePanel>

<!-- Hidden Link button for Async call back -->
<asp:UpdatePanel ID="updatePanel2" runat="server">
<ContentTemplate>
<asp:LinkButton ID="btnLoadData" onclick="btnLoadData_Click" runat="server" 
 Text="Fill GridView" CssClass="none"></asp:LinkButton> <!-- hidden-->

<a href="javascript: AsyncUpdateGridView()">A sync update</a>
<!-- testing purposes only-->

</ContentTemplate>
</asp:UpdatePanel>

so with this little hack i click hte linkbutton to update the gridview which works fine. 所以有了这个小技巧,我单击hte linkbutton更新gridview,它工作正常。 Eventually the AsyncUpdateGridView() which just calles the _dopostback method of the hidden linkbutton will be in Javascript. 最终,仅调用隐藏链接按钮的_dopostback方法的AsyncUpdateGridView()将使用Javascript。

The problem I have, is my GridView has columns which are Jquery DatePickers and Jquery fancy Drop Down Box's. 我的问题是,我的GridView的列为Jquery DatePickers和Jquery花式下拉框。 They are loaded with this javascript call: 他们加载了此javascript调用:

  function OnLoadPage() {
            $(".jqueryselector").selectbox({
                effect: "fade"
            });

            $(".jquerydatepicker").datepicker({ dateFormat: 'dd-mm-yy' });
        }

        $(document).ready(function () {
            OnLoadPage();
        }

The reason I made the OnLoadPage() function was because I tried calling that after I did the _DoPostBack call after the update. 之所以创建OnLoadPage()函数,是因为在更新之后我进行了_DoPostBack调用之后,我尝试调用该函数。

However this doesnt work. 但是,这不起作用。 So now when the page fist loads, all the jquery datepicker, drop down boxs and other fancy things I have work in the GridView. 因此,现在在页面拳头加载时,所有的jQuery datepicker,下拉框和其他我在GridView中都能使用的花哨的东西都可以使用。 But after the asynch Callback it reloads with all the default html. 但是在异步回调之后,它将使用所有默认的html重新加载。

$(document).ready is not executed after ajax panel call has finished and html block is updated. 在ajax面板调用完成和html块更新之后,不会执行$(document).ready You need to register to events provided by asp.net ajax for this. 您需要为此注册asp.net ajax提供的事件。 You can use begin_request and end_request for executing some javascript before and afterr ajax call, If you want to call the javascript function after the completion of ajax call you need to use end_request and for before ajax call you need begin_request, More about them over here 您可以使用begin_requestend_request之前和afterr Ajax调用执行一些JavaScript,如果你想调用的AJAX完成后的JavaScript函数调用,您需要使用END_REQUEST和之前Ajax调用需要begin_request,详细了解他们在这里

   function OnLoadPage() {
        $(".jqueryselector").selectbox({
            effect: "fade"
        });

        $(".jquerydatepicker").datepicker({ dateFormat: 'dd-mm-yy' });
    }


Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);


Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);


function BeginRequestHandler(sender, args)
{

}

function EndRequestHandler(sender, args)
{
     OnLoadPage();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM