DataRepeater _ItemCommand 事件在一段时间后停止触发
好吧,这是我一段时间以来见过的最奇怪的事情......
我正在使用 VS studio 2010 构建一个 asp.net(框架 4.0)网站。我的代码位于VB.Net中,我的测试浏览器是Firefox(最新版本),还在IE8和Google Chrome上进行了测试,行为相同。
基本上我在 UpdatePanel 的 DataRepeater 中有一个 LinkButton。 只要我定期使用该页面(每隔几分钟左右),_ItemCommand 事件就会触发。
问题是这样的:当我打开另一个网页(在另一个浏览器选项卡中)并在其上停留大约 1 小时左右,然后返回浏览器选项卡中的测试页面并单击 LinkButton 时,不会触发任何事件,并且该页面重新加载。就像按钮刚刚在我身上消失一样。
我首先认为这可能是会话超时问题,但我将 SessionID 记录在文本文件中,并且会话不会过期。 <<<<<使用新方法检测超时,
我可以确认(日志文件)问题的根源是 _ItemCommand 事件只是停止触发。我只是不知道为什么会这样。
我已经尝试了在类似问题(事件未触发)下提出的大多数解决方案,但我的问题完全不同,因为我的事件确实触发了......仅在有限的时间内触发。
我的中继器视图状态已启用。 我尝试将 LinkButton 更改为 Button,但没有遇到同样的问题。 我尝试过增加 ScryptManager 的 AsyncPostBackTimeout...也没有什么乐趣。 我尝试过 sessionState 模式=“StateServer”。 我尝试禁用我的 AVG Link Scanner。
所以请,任何想法......不要害羞,在这一点上我已经准备好考虑任何事情。
这是我现在用来检查会话超时的代码:
If Context.Session IsNot Nothing And Context.Session.IsNewSession _
And Page.Request.Headers("Cookie") IsNot Nothing _
And Page.Request.Headers("Cookie").IndexOf("ASP.NET_SessionId") >= 0 Then
'SESSION HAS TIMEDOUT
End If
这是页面标记
<asp:UpdatePanel ID="udpRSSFeeds" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cmdSearch" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="drpNewsFeed" EventName="ItemCommand" />
<asp:AsyncPostBackTrigger ControlID="cmdViewAll" EventName="Click" />
</Triggers>
<ContentTemplate>
<table class="Borderless" cellpadding="0" cellspacing="0" style="width:100%">
<tr><td class="lblHeaderText">NEWS FEEDS</td></tr>
<%--BEGIN: SEARCH GIZMO--%>
<tr><td>
<table class="Borderless" style="width:100%;" cellpadding="0" cellspacing="0">
<tr>
<td style="text-align:right; vertical-align:middle; height:32px;" >
<asp:TextBox ID="tbxSearchBox" runat="server" MaxLength="50" AutoCompleteType="None" Font-Size="16px" style="height:20px; width:187px; font-size:16px; border-style:solid; border-color:#54d242;" onfocus="Javascript:this.focus();this.select();" ></asp:TextBox>
</td>
<td style="text-align:left; vertical-align:middle; width:150px; height:32px;" >
<asp:ImageButton ID="cmdSearch" ImageUrl="~/GUIImages/cmdSearch.jpg" ToolTip="Search feed(s) for keyword(s)." Height="26px" Width="26px" runat="server" BorderStyle="None" ImageAlign="Middle" />
</td>
</tr>
</table>
</td></tr>
<%--END: SEARCH GIZMO--%>
<%--BEGIN FEED LIST--%>
<tr><td style="padding:3px 0px 3px 0px;"><asp:LinkButton ID="cmdViewAll" runat="server" CssClass="MenuItemActive" PostBackUrl="" CausesValidation="false" Text="* View ALL RSS Feeds"></asp:LinkButton></td></tr>
<asp:XmlDataSource ID="xdsNewsFeed" runat="server" DataFile="App_Data/RSSFeeds.xml" XPath="dataroot/qryRSSFeed"></asp:XmlDataSource>
<asp:Repeater ID="drpNewsFeed" runat="server" DataSourceID="xdsNewsFeed" EnableViewState="true" >
<ItemTemplate>
<tr><td style="padding:3px 0px 3px 0px;">
<asp:LinkButton ID="cmdSelectNewsFeed" runat="server" CssClass="MenuItem" CausesValidation="false" CommandName='<%#XPath("ID")%>'>- <%#XPath("Title")%></asp:LinkButton>
</td></tr>
</ItemTemplate>
</asp:Repeater>
<%--END FEED LIST--%>
<tr><td> </td></tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
这是后面的页面代码
Protected Sub drpNewsFeed_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles drpNewsFeed.ItemCommand
Dim oLogger As New nebLogManager("TESTNWOSGN.txt")
oLogger.TraceStart("drpNewsFeed_ItemCommand (" & Session.SessionID & ")")
'some code that never gets run because the event is not fired...
oLogger.TraceStop("drpNewsFeed_ItemCommand (" & Session.SessionID & ")")
End Sub
Protected Sub cmdSearch_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles cmdSearch.Click
Dim oLogger As New nebLogManager("TESTNWOSGN.txt")
oLogger.TraceStart("cmdSearch_Click (" & Session.SessionID & ")")
'some code that never gets run because the event is not fired...
oLogger.TraceStop("cmdSearch_Click (" & Session.SessionID & ")")
End Sub
不确定它是否重要,但它使用了 ScriptManager 上的 master_page
综合测试场景:
- 浏览至:http://www.nwosurvivalguide.com/NWOSGN.aspx
- 单击新闻源(左侧)
- 让我们坐 30 分钟
- 返回并单击另一个新闻源
结果 >>> >事件未触发但页面加载 Page_Init 检测到会话超时。 如果刷新页面,一切都会恢复正常。
Ok this is the weirdest thing I have seen in a while...
I am using VS studio 2010 to build a asp.net (framework 4.0) website. My code behind is in VB.Net, My testing browser is Firefox (latest version), also tested on IE8 and Google Chrome, same behavior.
Basically I have a LinkButton in a DataRepeater in a UpdatePanel.
The _ItemCommand event DOES FIRE for as long as I use the page regularly (every few minutes or so).
The problem is this: When I open another webpage (in another browser tab) and sit on it for like 1 hour or so and then come back to test page in the browser tab and click on the LinkButton, no event is fired and the page gets a reload. Like if the button had just died on me.
I first tough it might be a Session TimeOut issue but I logged the SessionID in a text file and the Session DOES NOT expire. <<<< Using new method for detecting TimeOut
I can confirm (logfiles) that the root of my problem is that the _ItemCommand event simply stops firing. I just have no idea why it does.
I have tried most solutions proposed under similar problems (event not firing) but my problem is positively different because my event DOES fire... Only for a limited time.
My Repeater ViewState is enabled.
I have tried changing the LinkButton for a Button but no joy same problem.
I have tried the uping the AsyncPostBackTimeout of the ScryptManager... no joy either.
I have tried sessionState mode="StateServer".
I have tried disabling my AVG Link Scanner.
So PLEASE, any idea... Don't be shy, at this point I'm ready to consider anything.
Here is the code I'm now using to check for Session Timeout:
If Context.Session IsNot Nothing And Context.Session.IsNewSession _
And Page.Request.Headers("Cookie") IsNot Nothing _
And Page.Request.Headers("Cookie").IndexOf("ASP.NET_SessionId") >= 0 Then
'SESSION HAS TIMEDOUT
End If
HERE IS THE PAGE MARKUP
<asp:UpdatePanel ID="udpRSSFeeds" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cmdSearch" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="drpNewsFeed" EventName="ItemCommand" />
<asp:AsyncPostBackTrigger ControlID="cmdViewAll" EventName="Click" />
</Triggers>
<ContentTemplate>
<table class="Borderless" cellpadding="0" cellspacing="0" style="width:100%">
<tr><td class="lblHeaderText">NEWS FEEDS</td></tr>
<%--BEGIN: SEARCH GIZMO--%>
<tr><td>
<table class="Borderless" style="width:100%;" cellpadding="0" cellspacing="0">
<tr>
<td style="text-align:right; vertical-align:middle; height:32px;" >
<asp:TextBox ID="tbxSearchBox" runat="server" MaxLength="50" AutoCompleteType="None" Font-Size="16px" style="height:20px; width:187px; font-size:16px; border-style:solid; border-color:#54d242;" onfocus="Javascript:this.focus();this.select();" ></asp:TextBox>
</td>
<td style="text-align:left; vertical-align:middle; width:150px; height:32px;" >
<asp:ImageButton ID="cmdSearch" ImageUrl="~/GUIImages/cmdSearch.jpg" ToolTip="Search feed(s) for keyword(s)." Height="26px" Width="26px" runat="server" BorderStyle="None" ImageAlign="Middle" />
</td>
</tr>
</table>
</td></tr>
<%--END: SEARCH GIZMO--%>
<%--BEGIN FEED LIST--%>
<tr><td style="padding:3px 0px 3px 0px;"><asp:LinkButton ID="cmdViewAll" runat="server" CssClass="MenuItemActive" PostBackUrl="" CausesValidation="false" Text="* View ALL RSS Feeds"></asp:LinkButton></td></tr>
<asp:XmlDataSource ID="xdsNewsFeed" runat="server" DataFile="App_Data/RSSFeeds.xml" XPath="dataroot/qryRSSFeed"></asp:XmlDataSource>
<asp:Repeater ID="drpNewsFeed" runat="server" DataSourceID="xdsNewsFeed" EnableViewState="true" >
<ItemTemplate>
<tr><td style="padding:3px 0px 3px 0px;">
<asp:LinkButton ID="cmdSelectNewsFeed" runat="server" CssClass="MenuItem" CausesValidation="false" CommandName='<%#XPath("ID")%>'>- <%#XPath("Title")%></asp:LinkButton>
</td></tr>
</ItemTemplate>
</asp:Repeater>
<%--END FEED LIST--%>
<tr><td> </td></tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
HERE IS THE PAGE CODE BEHIND
Protected Sub drpNewsFeed_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles drpNewsFeed.ItemCommand
Dim oLogger As New nebLogManager("TESTNWOSGN.txt")
oLogger.TraceStart("drpNewsFeed_ItemCommand (" & Session.SessionID & ")")
'some code that never gets run because the event is not fired...
oLogger.TraceStop("drpNewsFeed_ItemCommand (" & Session.SessionID & ")")
End Sub
Protected Sub cmdSearch_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles cmdSearch.Click
Dim oLogger As New nebLogManager("TESTNWOSGN.txt")
oLogger.TraceStart("cmdSearch_Click (" & Session.SessionID & ")")
'some code that never gets run because the event is not fired...
oLogger.TraceStop("cmdSearch_Click (" & Session.SessionID & ")")
End Sub
Not sure if its important but it uses a master_page on which sits the ScriptManager
COMPREHENSIVE TEST SCENARIO:
- BROWSE TO: http://www.nwosurvivalguide.com/NWOSGN.aspx
- CLICK on a News Feed (left side)
- LET sit for 30ish minutes
- GO BACK and click on another news feed
Result >>> Event not fired but page loads
Page_Init detects a Session Timeout.
If you refresh the page everything become functional again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,我要感谢 JHSOWTER 指出我的初始会话超时检测逻辑有缺陷。这确实让我回到了正轨。
所以问题是我的会话由于应用程序池回收而超时。
标准 SessionTimeout 解决方案不起作用,因为我位于控制应用程序池超时的共享主机上。
解决方案是将以下几行添加到 Web.Config 文件(在
标记内):为了生成我的机器密钥标记,我使用了此工具:
http://aspnetresources.com/tools/machineKey
经过这些更改后,我所有的问题都消失了。
再次非常感谢您的帮助。
First I wish to thank JHSOWTER for pointing out that my initial session timeout detection logic was flawed. That really sent me back on the right track.
So the problem was that my session was timing out due to application pool recycling.
The standard SessionTimeout solution would not work because I am on a shared hoster who controls the application pool timeout.
The SOLUTION was to add the following lines to the Web.Config file (within the
<system.web>
tag):To generate my machine key tag I used this tool:
http://aspnetresources.com/tools/machineKey
After those changes all my problems went away.
Again thanks a lot for the help.
我用谷歌搜索了一下,发现很多人因为 AVG Link Scanner 的原因而有类似的行为。
Firefox __doPostBack 在空闲时间后不工作
http://forums.asp.net/post/4021595.aspx
I have googled around for this and found a fair few people are having similar behaviour because of the AVG Link Scanner.
Firefox __doPostBack not working after idle time
http://forums.asp.net/post/4021595.aspx