1 System.Web.UI.ScriptManager.RegisterStartupScript来替代Page.ClientScript.RegisterStartupScript
2 注册DataItem方法
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<script type="text/javascript">...
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(
function(sender, e)
......{
var dataItem = e.get_dataItems()["<%= this.UpdatePanel1.ClientID %>"]();
alert(dataItem.Name);
});
</script>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="test" runat="server" Text="test" OnClick="test_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
using System.Web.Script.Serialization;
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void test_Click(object sender, EventArgs e)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
ScriptManager.GetCurrent(this.Page).RegisterDataItem(this.UpdatePanel1, "var _f = function(){alert('Hello World!');}; _f;", true);
}
}