开发者

How can I recall a javascript function after updatepanel update

<asp:UpdatePanel ID="UpdatePanel2" runat="server"
    OnLoad="UpdatePanel2_Load" UpdateMode="Conditional">
    <ContentTemplate>
        <script type="text/javascript">
            myFunction();
        </script>
        <asp:Label ID="Label1" runat="server" Text="1" Width="18px"></asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>

C#:

开发者_运维知识库
if(condition)
{
      UpdatePanel2.Update();
}
protected void UpdatePanel2_Load(object sender, EventArgs e)
{
        Label1.Text += 1;
}

the Label1's value is changing but it doesn't call myFunction(). I want to call it one more time after the some condition but not using setTimeout to auto call, some ideas?


When the UpdatePanel updates the DOM and rewrites script blocks into the DOM, they are not re-executed. You need to get on the client-side event that fires after the UpdatePanel is finished and re-execute your JS blocks:

<script type="text/javascript">
    function handleEndRequest(sender, args)
    {
        var panel = document.getElementById(sender._postBackSettings.panelID);
        var scripts = panel.getElementsByTagName('script');
        for(var i=0;i<scripts.length;i++) {
            eval(scripts[i].innerHTML);
        }
    }

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(handleEndRequest);
</script>


I have made it works by refreshing the whole page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜