ASPXGridview更新事件回调后执行jquery

发布于 2024-10-25 14:36:55 字数 309 浏览 1 评论 0原文

您好,我正在使用 DevExpress gridview,在更新事件时,我必须返回最终用户对话框消息,其中包含有关更新记录的信息

protected void AspxGrid_RowUpdated(object sender, ASPxDataUpdatedEventArgs e)
        {

//After updated return some info on client side as modal window for example
}

是否有任何内置功能可以实现所需的输出,或者有任何其他足够的方法来实现它?

Hi I'm working with DevExpress gridview and on updated event I have to return end user dialog message with the information about updated record

protected void AspxGrid_RowUpdated(object sender, ASPxDataUpdatedEventArgs e)
        {

//After updated return some info on client side as modal window for example
}

Is there any built in functionality to achieve desired output, or any other sufficient way to do it??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

长亭外,古道边 2024-11-01 14:36:55

要将信息传递给客户端,您应该执行 2 个不同的步骤:
1) 将一个新项目添加到 ASPxGridView 的 JSProperties 集合,其中将包含所需的信息:

ASPxGridView1.JSProperties.Add("cpInfo", "hi from server");

2) 处理 ASPxGridView 的客户端 EndCallback 事件以显示此消息:

  EndCallBack = "function(s,e) {
     if(typeof(s.cpInfo) != 'undefined')
        alert(s.cpInfo);

}"

编辑:
这是在这里工作的完整代码:

<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1"
    KeyFieldName="CategoryID" OnRowUpdated="ASPxGridView1_RowUpdated">
    <ClientSideEvents EndCallback="function(s, e) {
if(typeof(s.cpInfo) != 'undefined')
    alert(s.cpInfo);

}" />

protected void ASPxGridView1_RowUpdated(object sender, DevExpress.Web.Data.ASPxDataUpdatedEventArgs e) {
    (sender as ASPxGridView).JSProperties["cpInfo"] = "hi from server";
}

To pass the information to the client side, you should implement 2 different steps:
1) add a new item to the ASPxGridView's JSProperties collection which will contain the required info:

ASPxGridView1.JSProperties.Add("cpInfo", "hi from server");

2) handle the ASPxGridView's client side EndCallback event to show this message:

  EndCallBack = "function(s,e) {
     if(typeof(s.cpInfo) != 'undefined')
        alert(s.cpInfo);

}"

Edit:
Here is the complete code which works here:

<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1"
    KeyFieldName="CategoryID" OnRowUpdated="ASPxGridView1_RowUpdated">
    <ClientSideEvents EndCallback="function(s, e) {
if(typeof(s.cpInfo) != 'undefined')
    alert(s.cpInfo);

}" />

protected void ASPxGridView1_RowUpdated(object sender, DevExpress.Web.Data.ASPxDataUpdatedEventArgs e) {
    (sender as ASPxGridView).JSProperties["cpInfo"] = "hi from server";
}
忆依然 2024-11-01 14:36:55

您不能直接从服务器事件引发客户端事件。但实现目标的方法有很多种,最好的方法取决于具体情况。几种可能性...

1) 捕获异步回发后发生的客户端事件(如果您使用部分回发)。 Google Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded

2) 在代码中插入客户端脚本,该脚本将在页面加载完成后运行,例如

ScriptManager.RegisterStartupScript("someJavascriptFunction( );");

(即伪代码 - 您还需要包含其他参数)

3) 在服务器事件期间渲染某些内容,该事件将在页面加载完成时触发客户端事件。假设您正在使用 jQuery 和 $(document).ready() (并且不使用部分回发),您可以设置一个隐藏字段值,然后从客户端上的启动脚本检查该值并获取基于它你想要采取的任何行动。

如果您使用 updatepanels,则必须执行 #1 或 #2 - 因为 document.ready 启动代码在部分回发后不会重新运行。

You can't directly cause a client event from a server event. But there are a number of different ways to achieve the goal, the best one depends on the situation. A few possibilities...

1) Capture the client event that occurs after an async postback (if you're using partial postbacks). Google Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded

2) Insert a client script in code, which will be run after the page load is completed, e.g.

ScriptManager.RegisterStartupScript("someJavascriptFunction();");

(that is pseudocode - there are other parameters you need to include)

3) Render something during your server event that will trigger a client event when the page is done loading. Assuming you are using jQuery and $(document).ready() (and NOT using partial postbacks) you could set a hidden field value, and then check that value from the startup script on the client and take whatever action you want based on it.

If you're using updatepanels, you will have to do #1 or #2 - because document.ready startup code will not re-run after a partial postback.

空气里的味道 2024-11-01 14:36:55

请参阅有关此问题的回调的概念知识库文章。我希望它能帮助你。

Please refer to the The Concept of Callbacks KB article regarding this issue. I hope it will help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文