Asychnronous消息发送Asp.net [英] Asychnronous Message Send Asp.net

查看:135
本文介绍了Asychnronous消息发送Asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解AJAX的东西引擎盖下是如何工作的。说我有上有一个按钮,一个asp.net的形式。然后,我有一个数据库与单个列的DateTime 。当我点击按钮的asp.net表单上我要与当前时间插入到数据库中的列。

我有一个C#事件处理程序:

 保护无效btnButton_OnClick(EventArgs的发送,对象发件人)
{
    //插入DateTime.now到数据库
    //这部分很简单
}

我想这样的形式本身发生的是有按钮的点击不会重新加载的形式。它只是将消息发送到服务器;没有任何理由重新加载页面。有什么办法,我可以做到这一点?


  1. 我已经调查了AJAX框架一点点,好像这样可以更新面板内完成,但页面仍然会重新加载,它只是对用户少noticable。


  2. 在JavaScript中使用__doPostBack调用。我不知道这是如何工作的。



解决方案

这听起来像你偏爱微软提供的JavaScript库,这是罚款。在UpdatePanel和喜欢有自己的位置,但我发现,当你需要做的事情非常简单和直接的像你描述它是什么,更容易和更清洁的得到它直接调用做从Javascript服务器资源。

有很多方法可以做到这一点,但我喜欢用jQuery的$。阿贾克斯()方法(最近或MVC动作)调用Web服务方法。如果你愿意在这里考察一些稍微不同的技术,是一个博客文章会给你什么,我谈论的味道。

I'm trying to learn about how AJAX stuff works under the hood. Say I have an asp.net form with a button on it. I then have a database with a single column DateTime. When I click the button on the asp.net form I want to insert a column in the database with the current time.

I'll have a C# event handler:

protected void btnButton_OnClick(Eventargs e, object sender)
{
    //insert DateTime.now into DB
    //This part is easy
}

What I would like to happen on the form itself is to have the button click NOT reload the form. It would just send a message to the server; there is no reason for the page to reload. What are some ways I could accomplish this?

  1. I've looked into the AJAX framework a little bit and it seems like this could be done within an update panel, but the page would still reload, it would just be less noticable to the user.

  2. Use the __doPostBack call in javascript. I have no idea how this works.

解决方案

It sounds like you're partial to Microsoft's provided javascript libraries, which is fine. The UpdatePanel and the like have their place, but I've found that when you need to do something very simple and straightforward like what you're describing it is easier and cleaner to get it done with a direct call to a server resource from Javascript.

There are many ways to do this, but I like using jquery's $.ajax() method to invoke webservice methods (or MVC actions more recently). If you're willing to examine some slightly different technologies here's a blog post that will give you a taste of what I'm talking about.

这篇关于Asychnronous消息发送Asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆