使用jQuery Ajax更新GridView [英] Update GridView using jQuery Ajax
问题描述
我知道这个问题太多了,网上有这些:
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/ [ ^ ]
< a href =http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/> http://encosia.com/using-jquery-to-consume-aspnet-json-网络服务/ [ ^ ]
http: //encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/ [ ^ ]
我经历了所有之前发布的那些
这是我的方案,
我在一个页面上的UpdatePanel中有一个GirdView,我需要从另一个页面更新它。
听起来很简单,但很明显,当我使用静态web方法时,我无法引用UpdatePanel上的gridview,
这里是一些代码:
Page1.aspx
I know this has been asked too much and there are these on the net:
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/[^]
http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/[^]
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/[^]
I went through all of those before posting
Here''s my scenario,
I have a GirdView in an UpdatePanel on one page, and I need to update it from another page.
Sounds simple, but obviously, when I use a static webmethod, I cannot refer to the gridview on the UpdatePanel,
Here''s some code:
Page1.aspx
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script>
function update() {
jQuery.ajax({
url: 'Page2.aspx/GetData',
type: "POST",
data: "{'userid':" + userid + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.d);
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" value="click me" önclick="update();" />
</div>
<div>
</form>
</body>
Page2.aspx: - 这有网格和静态方法
Page2.aspx: - This has the grid and the static method
<head runat="server">
<title></title>
<script language=javascript>
function update() {
__doPostBack('UpdatePanel1', ''); //I can't call this!!
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID=UpdatePanel1 runat=server>
<ProgressTemplate>
WAIT!!!!
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel runat="server" ID="UpdatePanel1" onload="UpdatePanel1_Load">
<ContentTemplate>
<asp:GridView id=gv runat=server AutoGenerateColumns=true>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
page2.aspx.cs
page2.aspx.cs
[WebMethod()]
public static string GetData(int userid)
{
//UPDATE the GridView HERE!
}
protected void UpdatePanel1_Load(object sender, EventArgs e)
{
makeatableandbind();
}
我无法调用UpdatePanel1_Load或无法从静态方法引用GridView
我相信你们这里做过类似的事情
需要帮助
I cant call the UpdatePanel1_Load or cannot refer to the GridView from the static method
Im sure you guys here have done something like this
Need some help
推荐答案
解决方法是使用__doPostBack,非常简单
我没有时间分享解决方案....
这里是
Page 1
在更新面板中有gridview
第2页
有一些动作,之后它应该更新gridview第1页
Page1有一些类似的
The solution is to use __doPostBack, pretty simple
I didn''t have time to share the solution....
here goes
Page 1
has gridview in an updatepanel
page 2
has some action, after which it should update the gridview on page 1
Page1 has some javascript like
function refresh()
{
var btnid = '<%=btnUpdate.UniqueID%>'
__doPostBack(btnid, "OnClick");
}
带有gridview和按钮的更新面板
the the update panel with a gridview and a button
<asp:updatepanel id="UpdatePanel1" runat="server" onload="UpdatePanel1_Load" xmlns:asp="#unknown">
<contenttemplate>
<asp:gridview....>
</asp:gridview....></contenttemplate>
<triggers>
<asp:asyncpostbacktrigger controlid="btnUpdate" eventname="Click" />
</triggers>
</asp:updatepanel>
<asp:button id="btnUpdate" runat="server" style="display:none;" xmlns:asp="#unknown" />
和第2页
and on page 2
<script language="Javascript">
function RefreshParent() {
parent.refresh();
}
</script>
将此JavaScript函数称为:
call this JavaScript function like:
ClientScript.RegisterClientScriptBlock(this.GetType(), "afterSave", "refresh();", true);
希望这有帮助
Hope this helps
这篇关于使用jQuery Ajax更新GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!