解决AJAX中使用UpdatePanel后无法弹出js对话框问题(引)

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);
  }
}

博客园大道至简

http://www.cnblogs.com/jams742003/

转载请注明:博客园

上一篇:jQuery事件对象---常见属性


下一篇:使用Ajax和Jquery实现GridView的展开、合并