使用 ASP.NET 动态数据插入/编辑后返回上次查看的列表页面
对于相当标准的动态数据站点,当用户编辑或插入新项目并保存时,页面会执行 Response.Redirect(table.ListActionPath),这会将用户带回表的第 1 页。
如果他们正在编辑第 10 页(或其他页面)上的某个项目并想要编辑该页面上的下一个项目,他们必须记住页码并导航回该页。
让用户返回到他们上次查看的列表页面的最佳方式是什么?
我可以设想一些使用 cookie、会话状态或查询字符串值来保留此状态并制作自己的页面模板来合并它的解决方案,但我不禁认为这一定是创建动态数据时考虑到的事情,我在这里缺少的框架中一定有一些更简单或内置的东西。
With a pretty standard Dynamic Data site, when the user edits or inserts a new item and saves, the page does a Response.Redirect(table.ListActionPath), which takes the user back to page 1 of the table.
If they were editing an item on page 10 (or whatever) and want to edit the next item on that page, they have to remember the page number and navigate back to it.
What's the best way to return the user to the list page they last viewed?
I can conceive of some solutions using cookies, session state, or query string values to retain this state and making my own Page Template to incorporate it, but I can't help thinking this must be something that was considered when Dynamic Data was created, and there must be something simpler or built-in to the framework that I'm missing here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我有用;
在 ~/DynamicData/PageTemplates/List.aspx 中连接 onpageindexchanged 事件的处理程序:
然后在处理程序代码中,将页面索引保存到会话中:
最后,在页面加载时,如果请求不是回发,并且不是asyc postback,如果referrer url是edit.aspx,并且会话中有页面索引,则设置gridview的页面索引:
This is what worked for me;
In ~/DynamicData/PageTemplates/List.aspx wire-up a handler for the onpageindexchanged event:
Then in the hander code, save the page index to the session:
Finally, on page load, if the request is not postback, and is not asyc postback, and if the referrer url is edit.aspx, and if there is a page index in the session, set the page index of the gridview:
如果除了列表页面之外没有进入编辑页面,那么您可以使用 UrlReferrer 获取上一页并将其保留在页面的加载中,以防不回发(因为加载后会触发按钮的事件)页面的)在视图状态或隐藏字段中,当按钮事件被触发时被调用:
或者您可以使用javascript,
否则我认为您应该将列表页面的页码发送到标题或查询字符串中的编辑页面因此,完成编辑后,您应该重定向到编辑项目的列表页面。
If the page of editing is not enetered except from the listing page then you can use the UrlReferrer to get the previous page and keep it in the load of the page in case of not postingback (because the event of the button is fired after the load of the page) in a viewstate or in hiddenfield to be called when the button event is fired :
Or you can use javascript
else i think that you should send the page number of the listing page to the editing page in the header or in a querystring so after finishing editting you should redirect to the listing page at the item edited.
使用以下代码修改 Insert.aspx.cs 文件,该代码使用其来源的整个当前 QueryString 重定向列表模式 url:
Modify the Insert.aspx.cs file with the following code, that redirects list mode url with the whole current QueryString that it came from: