处理浏览器刷新 [英] Handling refreshes from browser

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

问题描述

我一直在寻找一种处理刷新的方法(用户按下刷新按钮)

并找到一段代码来检查网页是否刷新但是我不能

让它上班。


代码是:

***************** ********************************* **********

命名空间StevenBey.Web.UI


公共类页面

继承System.Web.UI.Page

Private _refreshState As Boolean

Private _isRefresh As Boolean

Public ReadOnly Property IsRefresh()As Boolean

Get

返回_isRefresh

结束获取

结束属性

受保护覆盖​​Sub LoadViewState(savedState作为对象)

Dim allStates As Object()= CType (savedState,Object())

MyBase.LoadViewState(allStates(0))

_refreshState = CBool​​(allStates(1))

_isRefresh = _refreshState = CBool​​(会话(__ ISREFRESH))

End Sub''LoadViewState

受保护的覆盖函数SaveViewState()As Object

Session(" __ ISREFRESH")= _ refreshState

Dim allStates(2)As Object

allStates(0)= MyBase.SaveViewState()

allStates(1)=不_refreshState

返回allStates

结束函数''SaveViewState

结束班''页


结束名称空间

*************** *********************************** **********


如果我这样做:


trace.warn("是Refresh =" &安培; Page.IsRefresh)





trace.warn("是Refresh ="& IsRefresh)

/>
我收到错误:


BC30456''IsRefresh''不是''System.Web.UI.Page'的成员''


我把编译后的版本(StevenBey.Web.UI.dll)放在我的Bin

目录中。


如果你看看跟踪页面你不会看到__RESREFRESH吗?


我还需要做些什么才能让它发挥作用吗?


谢谢,


汤姆

I was looking for a way to handle refreshes (user pressed refresh button)
and found a piece of code to check if a Web page was refreshed but I can''t
get it to work.

The code is:
************************************************** **********
Namespace StevenBey.Web.UI

Public Class Page
Inherits System.Web.UI.Page
Private _refreshState As Boolean
Private _isRefresh As Boolean
Public ReadOnly Property IsRefresh() As Boolean
Get
Return _isRefresh
End Get
End Property
Protected Overrides Sub LoadViewState(savedState As Object)
Dim allStates As Object() = CType(savedState, Object())
MyBase.LoadViewState(allStates(0))
_refreshState = CBool(allStates(1))
_isRefresh = _refreshState = CBool(Session("__ISREFRESH"))
End Sub ''LoadViewState
Protected Overrides Function SaveViewState() As Object
Session("__ISREFRESH") = _refreshState
Dim allStates(2) As Object
allStates(0) = MyBase.SaveViewState()
allStates(1) = Not _refreshState
Return allStates
End Function ''SaveViewState
End Class ''Page

End NameSpace
************************************************** **********

If I do a:

trace.warn("is Refresh = " & Page.IsRefresh)

or

trace.warn("is Refresh = " & IsRefresh)

I get the error:

BC30456 ''IsRefresh'' is not a member of ''System.Web.UI.Page''

I took the compiled version (StevenBey.Web.UI.dll) and put it in my Bin
directory.

If you look at trace page you won''t see __ISREFRESH?

Is there something else I need to do to get this to work?

Thanks,

Tom

推荐答案

嗨汤姆,


请参阅此处用户的评论:

http://jarednevans.typepad.com/techn..._techno_b.html

此方法在返回按钮时似乎失败被压了。你可以下载

a演示。


Tommaso


tshad ha scritto:
Hi Tom,

see the remarks here made by a User:

http://jarednevans.typepad.com/techn..._techno_b.html

this method seems to fail when back button is pressed. You can download
a demo.

Tommaso

tshad ha scritto:

我一直在寻找一种方法来处理刷新(用户按下刷新按钮)

并找到一段代码来检查网页是否刷新但是我可以'' t $ / $
让它上班。


代码为:

************ ************************************** **********

命名空间StevenBey.Web.UI


公共类页面

继承System.Web.UI.Page

Private _refreshState As Boolean

Private _isRefresh As Boolean


Public ReadOnly Property IsRefresh()As Boolean

Get

返回_isRefresh

结束获取

结束财产


受保护的覆盖Sub LoadViewState(savedState As Object)

Dim allStates As Object()= CType(savedState,Object())

MyBase.LoadV iewState(allStates(0))

_refreshState = CBool​​(allStates(1))

_isRefresh = _refreshState = CBool​​(Session(" __ ISREFRESH"))

End Sub''LoadViewState


受保护的覆盖函数SaveViewState()As Object

Session(" __ ISREFRESH")= _ refreshState

Dim allStates(2)As Object

allStates(0)= MyBase.SaveViewState()

allStates(1)=不_refreshState

返回所有状态

结束功能''SaveViewState

结束班''页


结束名称空间

************************************************ ** **********


如果我这样做:


trace.warn("是Refresh = " &安培; Page.IsRefresh)





trace.warn("是Refresh ="& IsRefresh)

/>
我收到错误:


BC30456''IsRefresh''不是''System.Web.UI.Page'的成员''


我把编译后的版本(StevenBey.Web.UI.dll)放在我的Bin

目录中。


如果你看看跟踪页面你不会看到__RESREFRESH吗?


我还需要做些什么才能让它发挥作用吗?


谢谢,


Tom
I was looking for a way to handle refreshes (user pressed refresh button)
and found a piece of code to check if a Web page was refreshed but I can''t
get it to work.

The code is:
************************************************** **********
Namespace StevenBey.Web.UI

Public Class Page
Inherits System.Web.UI.Page
Private _refreshState As Boolean
Private _isRefresh As Boolean
Public ReadOnly Property IsRefresh() As Boolean
Get
Return _isRefresh
End Get
End Property
Protected Overrides Sub LoadViewState(savedState As Object)
Dim allStates As Object() = CType(savedState, Object())
MyBase.LoadViewState(allStates(0))
_refreshState = CBool(allStates(1))
_isRefresh = _refreshState = CBool(Session("__ISREFRESH"))
End Sub ''LoadViewState
Protected Overrides Function SaveViewState() As Object
Session("__ISREFRESH") = _refreshState
Dim allStates(2) As Object
allStates(0) = MyBase.SaveViewState()
allStates(1) = Not _refreshState
Return allStates
End Function ''SaveViewState
End Class ''Page

End NameSpace
************************************************** **********

If I do a:

trace.warn("is Refresh = " & Page.IsRefresh)

or

trace.warn("is Refresh = " & IsRefresh)

I get the error:

BC30456 ''IsRefresh'' is not a member of ''System.Web.UI.Page''

I took the compiled version (StevenBey.Web.UI.dll) and put it in my Bin
directory.

If you look at trace page you won''t see __ISREFRESH?

Is there something else I need to do to get this to work?

Thanks,

Tom


在仔细阅读文章后,我能够让它工作。


************************************** ************ *****************

命名空间MyFunctions


公共类页面

继承System.Web.UI.Page

私有_refreshState为布尔值

私有_isRefresh为布尔值

Public ReadOnly属性IsRefresh()As布尔特

获取

返回_isRefresh

结束获取

结束财产

受保护的覆盖Sub LoadViewState(savedState As Object)

Dim allStates As Object()= CType(savedState,Object())

MyBase.LoadViewState(allStates(0))

_refreshState = CBool​​(allStates(1))

_isRefresh = _refreshState = CBool​​(会话(" __ ISREFRESH"))

End Sub''LoadViewState

受保护的覆盖函数SaveViewState()As Object

Session(" __ ISREFRESH")= _ refreshState

Dim allStates(2)As Object

allStates(0)= MyBase.SaveViewState()

allStates(1)=不_refreshState

返回所有状态

结束函数''SaveViewState


结束班''页


结束名称空间

******** *******************************************


在我的页面中,我必须添加一个继承:


<%@ Page Language = QUOT; VB"跟踪= QUOT;真" ContentType =" text / html"

ResponseEncoding =" iso-8859-1" Inherits =" MyFunctions.Page"%>

....

trace.warn(" is Refresh ="& IsRefresh())


然后就行了。


我对allStates的代码感到困惑。它是如何工作的。


在LoadViewState中:

Dim allStates As Object()= CType(savedState,Object())

MyBase.LoadViewState(allStates(0))

_refreshState = CBool​​(allStates(1))


似乎是从参数列表中获取savedState ,然后我认为

它正常传递所有状态的LoadViewState(0)(实际上只是

savedState - 所以为什么不通过savedState?)。


此外,什么是allStates(1)?


在SaveViewState中:

Dim allStates(2)As Object

allStates(0)= MyBase.SaveViewState()

allStates(1)=不_refreshState

返回所有状态


我假设MyBase.SaveViewState()正在执行普通的SaveViewState

并将更改后的ViewState传回allStates(0),这是什么

allStates(1 )为什么我们传回allStates - 这是否覆盖由M写出的

ViewState yBase.SaveViewState()?


谢谢,


Tom


< to ** ************@uniroma1.itwrote in message

news:11 ********************* @ m73g2000cwd.googlegro ups.com ...
I was able to get it to work after closer reading of the article.

************************************************** *****************
Namespace MyFunctions

Public Class Page
Inherits System.Web.UI.Page
Private _refreshState As Boolean
Private _isRefresh As Boolean
Public ReadOnly Property IsRefresh() As Boolean
Get
Return _isRefresh
End Get
End Property
Protected Overrides Sub LoadViewState(savedState As Object)
Dim allStates As Object() = CType(savedState, Object())
MyBase.LoadViewState(allStates(0))
_refreshState = CBool(allStates(1))
_isRefresh = _refreshState = CBool(Session("__ISREFRESH"))
End Sub ''LoadViewState
Protected Overrides Function SaveViewState() As Object
Session("__ISREFRESH") = _refreshState
Dim allStates(2) As Object
allStates(0) = MyBase.SaveViewState()
allStates(1) = Not _refreshState
Return allStates
End Function ''SaveViewState

End Class ''Page

End NameSpace
***********************************************

In my page, I have to add an inherits:

<%@ Page Language="VB" trace="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" Inherits="MyFunctions.Page"%>
....
trace.warn("is Refresh = " & IsRefresh())

Then it works.

I am confused as to the code with the "allStates" and how it works.

In LoadViewState:
Dim allStates As Object() = CType(savedState, Object())
MyBase.LoadViewState(allStates(0))
_refreshState = CBool(allStates(1))

It seems to be getting the savedState from the parameters list, then I think
it does the normal LoadViewState passing allStates(0) (which is really just
savedState - so why not just pass savedState??).

Also, what is allStates(1)?

In SaveViewState:
Dim allStates(2) As Object
allStates(0) = MyBase.SaveViewState()
allStates(1) = Not _refreshState
Return allStates

I assume the MyBase.SaveViewState() is just doing the normal SaveViewState
and passes back the changed ViewState into allStates(0), what is
allStates(1) and why are we passing back allStates - does this overwrite the
ViewState that was written out by MyBase.SaveViewState()?

Thanks,

Tom

<to**************@uniroma1.itwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...

嗨汤姆,


请看用户在此发表的评论:

http:// jarednevans。 typepad.com/techn..._techno_b.html


当按下后退按钮时,此方法似乎失败。你可以下载

a演示。


Tommaso


tshad ha scritto:
Hi Tom,

see the remarks here made by a User:

http://jarednevans.typepad.com/techn..._techno_b.html

this method seems to fail when back button is pressed. You can download
a demo.

Tommaso

tshad ha scritto:

>我正在寻找一种方法来处理刷新(用户按下刷新按钮)
并找到一段代码来检查网页是否刷新但是我可以'
让它工作。

代码是:
********************** *************************** ***********
命名空间StevenBey.Web.UI

公共类页面
继承System.Web.UI.Page
Private _refreshState As Boolean
Private _isRefresh As Boolean

Public ReadOnly Property IsRefresh( )作为布尔值
获取
返回_isRefresh
结束获取
结束属性

受保护的覆盖Sub LoadViewState(savedState As Object)
Dim allStates As Object()= CType(savedState,Object())
MyBase.LoadViewState(allStates(0))
_refreshState = CBool​​(allStates(1))
_isRefresh = _refr eshState = CBool​​(Session(" __ ISREFRESH"))
End Sub''LoadViewState

受保护的覆盖函数SaveViewState()As Object
Session(&__ ISREFRESH")= _ refreshState
Dim allStates(2)As Object
allStates(0)= MyBase.SaveViewState()
allStates(1)= Not _refreshState
返回allStates
结束函数'' SaveViewState
End Class''页

结束NameSpace
************************** *********************** ***********

如果我这样做:
trace.warn("是Refresh =" &安培; Page.IsRefresh)



trace.warn("是刷新=& IsRefresh)

我收到错误:

BC30456''IsRefresh''不是''System.Web.UI.Page'的成员''

我拿了编译版本(StevenBey.Web.UI.dll) )并把它放在我的Bin
目录中。

如果你看一下跟踪页面你不会看到__ISREFRESH?

还有什么我需要的东西吗?要做到这一点吗?

谢谢,

Tom
>I was looking for a way to handle refreshes (user pressed refresh button)
and found a piece of code to check if a Web page was refreshed but I
can''t
get it to work.

The code is:
************************************************* ***********
Namespace StevenBey.Web.UI

Public Class Page
Inherits System.Web.UI.Page
Private _refreshState As Boolean
Private _isRefresh As Boolean
Public ReadOnly Property IsRefresh() As Boolean
Get
Return _isRefresh
End Get
End Property
Protected Overrides Sub LoadViewState(savedState As Object)
Dim allStates As Object() = CType(savedState, Object())
MyBase.LoadViewState(allStates(0))
_refreshState = CBool(allStates(1))
_isRefresh = _refreshState = CBool(Session("__ISREFRESH"))
End Sub ''LoadViewState
Protected Overrides Function SaveViewState() As Object
Session("__ISREFRESH") = _refreshState
Dim allStates(2) As Object
allStates(0) = MyBase.SaveViewState()
allStates(1) = Not _refreshState
Return allStates
End Function ''SaveViewState
End Class ''Page

End NameSpace
************************************************* ***********

If I do a:

trace.warn("is Refresh = " & Page.IsRefresh)

or

trace.warn("is Refresh = " & IsRefresh)

I get the error:

BC30456 ''IsRefresh'' is not a member of ''System.Web.UI.Page''

I took the compiled version (StevenBey.Web.UI.dll) and put it in my Bin
directory.

If you look at trace page you won''t see __ISREFRESH?

Is there something else I need to do to get this to work?

Thanks,

Tom



但是后退按钮的问题呢。

我认为用户是对的。在这种情况下它不起作用。


(几乎)有趣的是,一个人复制了这篇文章,并且在代码项目中发布了它的
网站。

他还清楚地复制了这些错误... :)


Tommaso


tshad ha scritto:
But what about the back button problem.
I think that user was right. It doesn''t work in that case.

The (almost) funny thing is that a guy has copied this article and
published it on Code Project site.
He also copied the bugs clearly ... :)

Tommaso

tshad ha scritto:

仔细阅读文章后,我能够让它工作。


******* ******************************************* ******* **********

命名空间MyFunctions


公共类页面

继承System.Web.UI。 Page

Private _refreshState As Boolean

Private _isRefresh As Boolean


Public ReadOnly Property IsRefresh()As Boolean

获取

返回_isRefresh

结束获取

结束财产


受保护覆盖​​Sub LoadViewState (savedState As Object)

Dim allStates As Object()= CType(savedState,Object())

MyBase.LoadViewState(allStates(0))

_refreshState = CBool​​(allStates(1))

_isRefresh = _refreshState = CBool​​(会话(" __ ISREFRESH" ))

End Sub''LoadViewState


受保护的覆盖函数SaveViewState()As Object

Session(" __ ISREFRESH") = _refreshState

Dim allStates(2)As Object

allStates(0)= MyBase.SaveViewState()

allStates(1)= not _refreshState

返回所有状态

结束功能''SaveViewState


结束班''页


结束名称空间

************************************** *********


在我的页面中,我必须添加一个继承:


<%@ Page Language = QUOT; VB"跟踪= QUOT;真" ContentType =" text / html"

ResponseEncoding =" iso-8859-1" Inherits =" MyFunctions.Page"%>

...

trace.warn(" is Refresh ="& IsRefresh())


然后就行了。


我对allStates的代码感到困惑它是如何工作的。


在LoadViewState中:

Dim allStates As Object()= CType(savedState,Object())

MyBase.LoadViewState(allStates(0))

_refreshState = CBool​​(allStates(1))


似乎是从参数列表中获取savedState ,然后我认为

它正常传递所有状态的LoadViewState(0)(实际上只是

savedState - 所以为什么不通过savedState?)。


此外,什么是allStates(1)?


在SaveViewState中:

Dim allStates(2)As Object

allStates(0)= MyBase.SaveViewState()

allStates(1)=不_refreshState

返回所有状态


我假设MyBase.SaveViewState()正在执行普通的SaveViewState

并将更改后的ViewState传回allStates(0),这是什么

allStates(1 )为什么我们传回所有状态 - 这是否覆盖了

ViewState由MyBase.SaveViewState()写出来?


谢谢,


Tom


< to**************@uniroma1.itwrote in message

news:11 ****************** ***@m73g2000cwd.googlegro ups.com ...
I was able to get it to work after closer reading of the article.

************************************************** *****************
Namespace MyFunctions

Public Class Page
Inherits System.Web.UI.Page
Private _refreshState As Boolean
Private _isRefresh As Boolean
Public ReadOnly Property IsRefresh() As Boolean
Get
Return _isRefresh
End Get
End Property
Protected Overrides Sub LoadViewState(savedState As Object)
Dim allStates As Object() = CType(savedState, Object())
MyBase.LoadViewState(allStates(0))
_refreshState = CBool(allStates(1))
_isRefresh = _refreshState = CBool(Session("__ISREFRESH"))
End Sub ''LoadViewState
Protected Overrides Function SaveViewState() As Object
Session("__ISREFRESH") = _refreshState
Dim allStates(2) As Object
allStates(0) = MyBase.SaveViewState()
allStates(1) = Not _refreshState
Return allStates
End Function ''SaveViewState

End Class ''Page

End NameSpace
***********************************************

In my page, I have to add an inherits:

<%@ Page Language="VB" trace="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" Inherits="MyFunctions.Page"%>
...
trace.warn("is Refresh = " & IsRefresh())

Then it works.

I am confused as to the code with the "allStates" and how it works.

In LoadViewState:
Dim allStates As Object() = CType(savedState, Object())
MyBase.LoadViewState(allStates(0))
_refreshState = CBool(allStates(1))

It seems to be getting the savedState from the parameters list, then I think
it does the normal LoadViewState passing allStates(0) (which is really just
savedState - so why not just pass savedState??).

Also, what is allStates(1)?

In SaveViewState:
Dim allStates(2) As Object
allStates(0) = MyBase.SaveViewState()
allStates(1) = Not _refreshState
Return allStates

I assume the MyBase.SaveViewState() is just doing the normal SaveViewState
and passes back the changed ViewState into allStates(0), what is
allStates(1) and why are we passing back allStates - does this overwrite the
ViewState that was written out by MyBase.SaveViewState()?

Thanks,

Tom

<to**************@uniroma1.itwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...

嗨汤姆,


请看这里的评论用户:

http:/ /jarednevans.typepad.com/techn..._techno_b.html


当按下后退按钮时,此方法似乎失败。你可以下载

a演示。


Tommaso


tshad ha scritto:
Hi Tom,

see the remarks here made by a User:

http://jarednevans.typepad.com/techn..._techno_b.html

this method seems to fail when back button is pressed. You can download
a demo.

Tommaso

tshad ha scritto:

我一直在寻找一种方法来处理刷新(用户按下刷新按钮)

并找到一段代码来检查网页是否刷新了但是我

不能

让它上班。


代码是:

**** ********************************************** **** ******

命名空间StevenBey.Web.UI

公共类页面

继承System.Web.UI。 Page

Private _refreshState As Boolean

Private _isRefresh As Boolean


Public ReadOnly Property IsRefresh()As Boolean

获取

返回_isRefresh

结束获取

结束财产


受保护覆盖​​Sub LoadViewState (savedState As Object)

Dim allStates As Object()= CType(savedState,Object())

MyBase.LoadViewState(allStates(0))

_refreshState = CBool​​(allStates(1))

_isRefresh = _refreshState = CBool​​(Session(" __ ISREFRESH"))

End Sub''LoadViewState


受保护的覆盖函数SaveViewState()As Object

Session(" __ ISREFRESH")= _ refreshState

Dim allStates(2)As Object

allStates(0)= MyBase.SaveViewState()

allStates(1)=不_refreshState

返回所有状态

结束功能''SaveViewState

结束班''页


********************************************** **** **********


如果我这样做:


trace.warn("是刷新= &安培; Page.IsRefresh)





trace.warn("是Refresh ="& IsRefresh)

/>
我收到错误:


BC30456''IsRefresh''不是''System.Web.UI.Page'的成员''


我把编译后的版本(StevenBey.Web.UI.dll)放在我的Bin

目录中。


如果你看看跟踪页面你不会看到__RESREFRESH吗?


我还需要做些什么才能让它发挥作用吗?


谢谢,


Tom
I was looking for a way to handle refreshes (user pressed refresh button)
and found a piece of code to check if a Web page was refreshed but I
can''t
get it to work.

The code is:
************************************************** **********
Namespace StevenBey.Web.UI

Public Class Page
Inherits System.Web.UI.Page
Private _refreshState As Boolean
Private _isRefresh As Boolean
Public ReadOnly Property IsRefresh() As Boolean
Get
Return _isRefresh
End Get
End Property
Protected Overrides Sub LoadViewState(savedState As Object)
Dim allStates As Object() = CType(savedState, Object())
MyBase.LoadViewState(allStates(0))
_refreshState = CBool(allStates(1))
_isRefresh = _refreshState = CBool(Session("__ISREFRESH"))
End Sub ''LoadViewState
Protected Overrides Function SaveViewState() As Object
Session("__ISREFRESH") = _refreshState
Dim allStates(2) As Object
allStates(0) = MyBase.SaveViewState()
allStates(1) = Not _refreshState
Return allStates
End Function ''SaveViewState
End Class ''Page

End NameSpace
************************************************** **********

If I do a:

trace.warn("is Refresh = " & Page.IsRefresh)

or

trace.warn("is Refresh = " & IsRefresh)

I get the error:

BC30456 ''IsRefresh'' is not a member of ''System.Web.UI.Page''

I took the compiled version (StevenBey.Web.UI.dll) and put it in my Bin
directory.

If you look at trace page you won''t see __ISREFRESH?

Is there something else I need to do to get this to work?

Thanks,

Tom


这篇关于处理浏览器刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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