本文介绍了如何避免生命周期黑客攻击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 ASP.NET模型被吹捧为开发网页的一种干净的OO方法, 但有时页面生命周期构成了愚蠢的障碍,迫使你恢复到b $ b Olde ASP 3.0方式。 这里是ASPX页面的大致轮廓: ....一堆标准控件。 .. PagingNav ResultSetDisplay SubmitButton 基本上,PagingNav允许用户导航通过DB结果 set; ResultSetDisplay显示数据列表中当前选定的页面; 和SubmitButton用于用户更改条件并希望 更新视图。 现在,PagingNav控件需要知道数据库中找到的记录总数 ,因此查询必须在呈现之前被激活。因此我需要在PagingNav的PreRender事件之前执行查询,其中 表示我不能,例如,在 ResultSetDisplay控件,因为它将在PagingNav控件的PreRender事件后执行 (由于它在页面中的位置)。换句话说, 对于PageNavControl来说,找出查询找到的总记录数太晚了。我可以在PreRender之前触发的ResultSetDisplay 的任何事件中执行查询。到目前为止一直很好。 输入SubmitButton控件,这会搞乱整个计划。问题 是,我想在这个按钮被点击的时候将当前页码重置为1。所以我在其SubmitButton_Click中添加代码来做到这一点。唉,这个事件 在ResultSetDisplay的Load事件之后执行,并且在它的 PreRender事件之前执行。这意味着让ResultSetDisplay显示 适当的页面(即#1),我必须在SubmitButton_Click事件之后发生 的事件中执行查询,这是PreRender事件。 但是这几乎搞砸了PagingNav控件,因为如上面所解释的那样,它需要找出查询找到的记录数,但是现在已经很晚了。 所以,为了解决这个问题,我必须恢复到ASP 3.0 hacks并添加一些东西在ResultSetDispay的Load事件中,例如: if(Request.Form [" update"]!= null) this .currentPage = 1; 这完全违背了ASP.NET的OO风格。 所以我的问题是,你们怎么样?整齐地解决这个问题? 解决方案 将 列表; 到的PreRender事件中执行查询 事件 即, 记录 问题 事件)之后发生的事件中执行查询。 事件。 The ASP.NET model is touted as a clean OO approach to developing web pages,yet sometimes the page lifecycle poses silly obstacles that forces you revertto the Olde ASP 3.0 Ways. Here''s a rough outline of an ASPX page: .... a bunch of criteria controls...PagingNavResultSetDisplaySubmitButton Basically, the PagingNav allows the user to navigate through the DB resultset; the ResultSetDisplay shows the currently selected page in a data list;and the SubmitButton is used in case the user changed criteria and wants toupdate the view. Now, the PagingNav control needs to know the total number of records foundin the DB, so the query must be exectued before it''s rendered. Therefore Ihave to execute the query before the PreRender event of PagingNav, whichmeans I cannot, for example, execute the query in the PreRender event of theResultSetDisplay control since it will be executed after the PreRender eventof the PagingNav control (due to its position in the page). In other words,it would be too late for the PageNavControl to figure out the total recordsthe query found. I can execute the query in any event of ResultSetDisplaythat fires before PreRender. So far so good. Enter the SubmitButton control, which messes up the whole plan. The problemis, I want to reset the current page number to 1 whenever this button isclicked. So I add code to do that in its SubmitButton_Click. Alas, this eventexecutes AFTER the Load event of the ResultSetDisplay and BEFORE itsPreRender event. This means to get the ResultSetDisplay to dispay theappropriate page (i.e. # 1), I have to excute the query in an event thattakes place after the SubmitButton_Click event, which is the PreRender event.But that pretty much screws up the PagingNav control since, as explainedabove, it needs to find out how many records the query found, but it''s toolate now. So, to fix the problem, I have to revert to ASP 3.0 hacks and add somethingin the Load event of the ResultSetDispay such as: if (Request.Form["update"] != null)this.currentPage = 1; which is totally against the OO style of ASP.NET. So my question is, how would you guys solve such a problem neatly? 解决方案 pages, revert list; to the event words, records problem event event. something 这篇关于如何避免生命周期黑客攻击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-21 13:32