RadGrid 中 点击编辑某条记录,弹出窗口, 关闭窗口后,想让RadGrid自动刷新一下, 大家碰到过不?
官方网站上有专门的说明文档:
Making postback/AJAX request from javascript in user control/webform/MasterPage
一、“用户控件”的使用。
后台代码:
C# | |
---|---|
public class WebUserControl1 : System.Web.UI.UserControl, IPostBackEventHandler
{ public void RaisePostBackEvent(string eventArgument) { switch(eventArgument) } |
前台代码:
var radGrid1_ClientID = "<%=RadGrid1.ClientID %>";
注意:这里取的是控件页面的UniqueID,如果是WebForm页面,这里的值应为"<%=RadGrid1.ClientID %>"
var radGrid1_UniqueID = "<%=this.UniqueID %>";
window[radGrid1_ClientID].AjaxRequest(radGrid1_UniqueID, "Rebind");
参数说明:
__doPostBack(eventTarget, eventArgument) or RadGridClientObject.AjaxRequest(eventTarget, eventArgument) |
||
eventTarget | The control which should raise postback event. If this control is directly on the HtmlForm, you can use the control's UniqueID or ClientID. Otherwise if your control is in a INamingContainer, you must use the control's UniqueID. For UserControl you should use always the user control's UniqueID | |
eventArgument | This is optional argument for the event, used for passing some data on the server (which can be processed further) |
eventArgument:主要用来判断是从哪个地方返回来刷新数据的。
二、MasterPage页面的使用
1.如果RadGrid在asp:ContentPlaceHolder 里:
后台代码:
C# | |
---|---|
public partial class MasterPage : System.Web.UI.MasterPage, IPostBackEventHandler
{ public void RaisePostBackEvent(string eventArgument) { switch (eventArgument) { case "Rebind": RadGrid1.Rebind(); break; } } } |
前台代码:
2.如果RadGrid在asp:Content里:
后台代码:
C# | |
---|---|
protected void chkIsClosed_PreRender(object source, System.EventArgs e)
{ (source as CheckBox).Attributes("onclick") = "PerformRequest()"; } |
三、ASPX页面的使用
后台代码:
C# | |
---|---|
protected override void RaisePostBackEvent(IPostBackEventHandler source, String eventArgument)
{ base.RaisePostBackEvent(source, eventArgument); switch(eventArgument) { case "Rebind": RadGrid1.Rebind(); break; } } |
前台代码:
RadGrid 中的很多功能需要再仔细的挖掘,希望对大家的工作有所帮助。
欢迎交流。