简体   繁体   English

Sharepoint WebPart回发问题

[英]Sharepoint webpart postback issue

I created a treeview webpart, and if you click a node, it modifies a SPList, and clears and recreates the treeview. 我创建了一个Treeview Web部件,如果您单击一个节点,它将修改SPList,并清除并重新创建TreeView。

So when I click a node, the page gets refreshed, then the treeview function occurs and edits the list and recreates the treeview. 因此,当我单击一个节点时,页面将刷新,然后出现树视图功能并编辑列表并重新创建树视图。 THEN the problem is if I were to refresh the page by hitting F5, the same thing happens again ie the List gets modified again even though i didn't click a node. 然后的问题是,如果我要通过按F5刷新页面,则会再次发生相同的事情,即即使我没有单击节点,列表也会被再次修改。

I suspect something like the treeview node select change event was activated again. 我怀疑类似树视图节点选择更改事件的事件再次被激活。

As well this happens when I hit refresh: 当我点击刷新时也会发生这种情况:

在此处输入图片说明

Is it somehow resending the tree click flag or something? 是否以某种方式重新发送树形单击标志或其他内容? How can I clear it when refreshing so it doesn't try to resend it? 刷新时如何清除它,这样它就不会尝试重新发送它?

There are two common approaches for preventing actions performed on postback from being called repeatedly by user's refreshing the page: 有两种常见的方法可以防止用户刷新页面重复调用回发操作:

  1. In whatever code that they are running do some sort of check to see if they have already done what they are about to do. 他们在运行的任何代码中都进行某种检查,以查看他们是否已经完成了将要执行的操作。 Sometimes this is easy (ie they clicked to delete an item, but I see it's already deleted) and sometimes it's just not possible or practical. 有时这很容易(例如,他们单击以删除项目,但我看到它已被删除),有时这是不可能的或不切实际的。

  2. After performing the postback that you don't want to be repeated do a Response.Redirect (to either another page, or even just the same page). 执行不想重复的回发后,执行Response.Redirect (到另一个页面,甚至只是同一页面)。 By doing this when they hit refresh their 'last action' won't be the pastback, it will be the result of the redirect. 这样,当他们点击刷新时,他们的“最后动作”就不会成为过去,这将是重定向的结果。 Of course, if they start using their history to go 'back' they could easily end up redoing whatever action you had done before. 当然,如果他们开始使用自己的历史记录进行“追溯”,则很容易最终重做您之前所做的任何操作。 This course of action isn't stopping them from intentionally (or maliciously) duplicating the action, it's just allowing them to hit 'refresh' without accidentally duplicating the action. 此操作过程并没有阻止他们有意(或恶意)复制操作,而只是允许他们进行“刷新”而不会意外复制操作。 Also note that this comes with a cost. 另请注意,这是有代价的。 You will need perform another back and forth with the client, and you'll need to re-generate the entire page (this will likely have a performance cost, and potentially be difficult to implement as well, depending on the specifics). 您将需要与客户端来回执行另一个操作,并且您将需要重新生成整个页面(这可能会带来性能成本,并且根据具体情况可能也难以实施)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM