Last active
January 7, 2016 16:07
-
-
Save malbert69/f687055b9990923905d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="do-after-load.ascx.cs" Inherits="controls.DoAfterLoad" %> | |
<asp:UpdatePanel runat="server" UpdateMode="Always"> | |
<ContentTemplate> | |
<asp:HiddenField runat="server" ID="DoAfterLoadJavaScriptHiddenField" /> | |
</ContentTemplate> | |
</asp:UpdatePanel> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace MpFloors.controls | |
{ | |
public partial class DoAfterLoad : System.Web.UI.UserControl | |
{ | |
private Dictionary<object, string> _scripts = new Dictionary<object, string>(); | |
//public string DoAfterLoadJavaScript { get; set; } | |
public void AddDoAfterLoadJavaScript(object key, string script) | |
{ | |
_scripts[key] = script; | |
} | |
public void Clear() | |
{ | |
_scripts.Clear(); | |
} | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
Page.ClientScript.RegisterStartupScript( | |
GetType(), | |
"DoAfterLoadJavaScriptEngine", | |
@" | |
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function(s, e) { | |
$(""[id$='_DoAfterLoadJavaScriptHiddenField']"").each(function() {eval(this.value)}); | |
}); | |
", true); | |
} | |
protected void Page_PreRender(object sender, EventArgs e) | |
{ | |
DoAfterLoadJavaScriptHiddenField.Value = string.Join(";", | |
_scripts.Where(item => !string.IsNullOrWhiteSpace(item.Value)).Select(item => item.Value.TrimEnd(';'))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment