ASP.NET问题 [英] ASP.NET Question

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

问题描述

如何从服务器进行PostBack调用,以便我可以在客户端Web浏览器上更新某些内容?客户端只有打开的页面才是客户端的事件。但我想从服务器推送一些内容,以便客户端网页重新加载新信息。代码示例请


Shreyash

How do I make PostBack Call from the Server so that I can update something on the client web browser? The Client just has the page open theres is no event from the Client. But I want to push something from the server so that the client webpage reloads with the new information. Code Sample Please

Shreyash

推荐答案

nope ....

http是请求/响应...不是基于推送。

-

Curt Christianson

所有者/首席开发人员,DF-软件
www.Darkfalz.com

" Shreyash Patel" <一个******* @ discussions.microsoft.com>在消息中写道

新闻:0B ********************************** @ microsof t.com ...
nope....
http is Request/Response... not push based.
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Shreyash Patel" <an*******@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
如何从服务器进行PostBack调用,以便我可以在客户端Web浏览器上更新
?客户只是打开了来自客户端的没有

事件的页面。但是我想从服务器推送一些东西,以便客户网页重新加载新信息

。代码示例请?
Shreyash
How do I make PostBack Call from the Server so that I can update something on the client web browser? The Client just has the page open theres is no
event from the Client. But I want to push something from the server so that
the client webpage reloads with the new information. Code Sample Please?
Shreyash



然后ASP.NET Chat永远不可能。 ASP.NET for Dummies实现了一个仅使用ASP.NET创建的聊天室应用程序。必须有一些方法可以强制客户页面刷新或更新。
Then ASP.NET Chat would never be possible. The ASP.NET for Dummies has a implementation of a Chat Room Applicaiton created just using ASP.NET. There must be some way of forcing the client page to refresh or update.


我们的网站上有类似的东西。查看
www.myfloridahouse.com/session_live_preview.aspx 。我们必须每60秒向用户更新

信息,以便用户知道房子是否是另一个账单和/或修改。我们通过使用以下代码每60秒设置一次

autopost来实现这一点:


private void RegisterRefreshScript()

{

//注册一个脚本,每隔这么多秒自动回发

//注意:设置要刷新的元标记不会执行(POST BACK)

int refreshRate =

Convert.ToInt32(ConfigurationSettings.AppSettings [" SessionLiveRefreshRate"])

;

StringBuilder scriptBlock = new StringBuilder();

scriptBlock.Append("< script>");

scriptBlock.Append(" function sessionLive_autoPostBack()");

scriptBlock.Append(" {");

scriptBlock.Append(" __ doPostBack(''lnkPostBack'','''');");

scriptBlock.Append("}");

scriptBlock.Append(" window.setInterval(''sessionLive_autoPostBack()'',");

scriptBlock.Append(refreshRate .ToString());

scriptBlock.Append("); ");

scriptBlock.Append("< / script>");

RegisterStartupScript(" autoPostBack",scriptBlock.ToString());

}


如果你每次回发时调用此函数,你都可以被告知

,浏览器会回发每隔这么多秒到服务器。不要
让这让你感到困惑,lnkPostBack只是一个服务器端链接按钮

在ASPX页面上声明如下:


< asp:LinkBut​​ton ID =" lnkPostBack" Runat =" server">< / asp:LinkBut​​ton>


有什么好处,当回发后它会调用

lnkPostBack_Click事件(只要你设置了一个事件),所以你知道用户点击刷新按钮,其他可能导致的b / b按钮之间的差异
回复,并添加了

的注册脚本块。


让我知道这是否可以帮助你!


谢谢,

" Shreyash Patel" <一个******* @ discussions.microsoft.com>在消息中写道

新闻:0B ********************************** @ microsof t.com ...
We have something similar on our site. check out
www.myfloridahouse.com/session_live_preview.aspx. We have to update
information to the user every 60 seconds so the user knows if the House is
dicussing another bill and/or amendment. We achived this by setting an
autopost back every 60 seconds with the following code:

private void RegisterRefreshScript()
{
// register a script to auto post back every so many seconds
// NOTE: Setting a meta tag to refresh will not do a (POST BACK)
int refreshRate =
Convert.ToInt32(ConfigurationSettings.AppSettings["SessionLiveRefreshRate"])
;
StringBuilder scriptBlock = new StringBuilder();
scriptBlock.Append( "<script>" );
scriptBlock.Append( "function sessionLive_autoPostBack() ");
scriptBlock.Append( "{ " );
scriptBlock.Append( " __doPostBack(''lnkPostBack'','''');");
scriptBlock.Append( "} " );
scriptBlock.Append( "window.setInterval( ''sessionLive_autoPostBack()'', ");
scriptBlock.Append( refreshRate.ToString() );
scriptBlock.Append( "); ");
scriptBlock.Append( "</script>" );
RegisterStartupScript( "autoPostBack", scriptBlock.ToString() );
}

If you call this function each time there is a postback, you can be assurred
that the brower will post back to the server every so many seconds. Don''t
let this confuse you, the lnkPostBack is just a server side link button
declare on the ASPX page like so:

<asp:LinkButton ID="lnkPostBack" Runat="server"></asp:LinkButton>

What is nice is that that when the post back happens it will call the
lnkPostBack_Click event (so long as you have an event for it set up) so you
know the difference between the user clicking the refresh button, other
buttons that may cause a post back, and the registered script block that was
added.

Let me know if this helps you out!

Thanks,
"Shreyash Patel" <an*******@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
如何从服务器进行PostBack调用,以便我可以在客户端Web浏览器上更新
?客户只是打开了来自客户端的没有

事件的页面。但是我想从服务器推送一些东西,以便客户网页重新加载新信息

。代码示例请?
Shreyash
How do I make PostBack Call from the Server so that I can update something on the client web browser? The Client just has the page open theres is no
event from the Client. But I want to push something from the server so that
the client webpage reloads with the new information. Code Sample Please?
Shreyash



这篇关于ASP.NET问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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