How to have a javascript callback executed after an update panel postback?

后端 未结 5 1507
攒了一身酷
攒了一身酷 2020-11-27 11:52

I\'m using a jQuery tip plugin to show help tips when the user hovers certain elements of the page.

I need to register the plugin events after the page is loaded usi

5条回答
  •  渐次进展
    2020-11-27 12:26

    This is probably far from the most elegant solution, but its a solution nonetheless:

    public class UpdatePanel : System.Web.UI.UpdatePanel
    {
        /// 
        /// Javascript to be run when the updatepanel has completed updating
        /// 
        [Description("Javascript to be run when the updatepanel has completed updating"),
            Category("Values"),
            DefaultValue(null),
            Browsable(true)]
        public string OnUpdateCompleteClientScript
        {
            get
            {
                return (string)ViewState["OnUpdateCompleteClientScript"];
            }
            set
            {
                ViewState["OnUpdateCompleteClientScript"] = value;
            }
        }
    
        protected override void OnPreRender(System.EventArgs e)
        {
            base.OnPreRender(e);
            if(!string.IsNullOrEmpty(this.OnUpdateCompleteClientScript))
                Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, string.Concat("Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(sender, args){for(var panelId in sender._updatePanelClientIDs){if(sender._updatePanelClientIDs[panelId] == '", this.ClientID, "'){", this.OnUpdateCompleteClientScript, "}}});"), true);
        }
    }
    

    Use it like this:

    
        
    
    

    Of course you'll need to register the custom control in youre webconfig or page to use it like this.

    Edit: also, have you looked at jquery.live?

提交回复
热议问题