I have written an application in ASP.net, that is designed to let the user add records to a database. The page is set up that when a user adds a record, the ID number of the newly added record is set in session, the page Response.Redirects to a "Thank you for submitting" page, then redirects back to the original page to allow further edits. Users can also use the Back button on this screen to go back to the original record adding page, which allows them to make edits to the data.
我在ASP.net中编写了一个应用程序,旨在让用户将记录添加到数据库中。页面设置为当用户添加记录时,新添加的记录的ID号在会话中设置,页面Response.Redirects到“谢谢你提交”页面,然后重定向回原始页面以允许进一步编辑。用户还可以使用此屏幕上的“返回”按钮返回到原始记录添加页面,这使他们可以对数据进行编辑。
However, I have found that storing the ID in session isn't a terribly good solution, as a user might try to create two documents in different tabs or windows. I have also tried setting the ID in a literal control, but this causes the problem that when the user uses the Back button, the literal control isn't set to the ID, and new records get added instead of one being edited.
但是,我发现在会话中存储ID并不是一个非常好的解决方案,因为用户可能会尝试在不同的选项卡或窗口中创建两个文档。我还尝试在文字控件中设置ID,但这会导致以下问题:当用户使用“返回”按钮时,文字控件未设置为ID,并且添加了新记录而不是正在编辑的记录。
Is there any kind of solution for this?
对此有什么解决方案吗?
7 个解决方案
#1
Silly question, why can the user use the back button to edit the data just accepted in a post?
愚蠢的问题,为什么用户可以使用后退按钮编辑刚刚在帖子中接受的数据?
If the edit previously posted data is a common scenario why not just redirect to a page when the data is accepted that lets them edit it. Then if the hit the back button they would be going back to the original "clean" insert/add new data page.
如果编辑以前发布的数据是一种常见的情况,为什么不只是在接受数据时重定向到页面,让他们编辑它。然后,如果点击后退按钮,他们将返回到原始的“干净”插入/添加新数据页面。
This would give the following flows Add->[Post]->Edit->..... Add->[Post]->Edit->[Back button]->Add->[Post]->Edit->[Post]->Edit....
这将给出以下流程Add - > [Post] - > Edit - > ..... Add - > [Post] - > Edit - > [Back button] - > Add - > [Post] - > Edit-> [发布] - >编辑....
#2
I'd recommend storing your ID in the QueryString. After the record is added, redirect to your "thankyou" page, which then I am guessing contains a link to the edit form which you will generate with the ID in the querystring. When that link is followed, the edit page shouild pull the ID out of the query string in order to load up the correct record to edit.
我建议将您的ID存储在QueryString中。添加记录后,重定向到“thankyou”页面,然后我猜测它包含一个指向编辑表单的链接,您将使用查询字符串中的ID生成该表单。当遵循该链接时,编辑页面应该从查询字符串中提取ID,以便加载要编辑的正确记录。
Your add and edit form can even be the same page, when an ID is provided in the querystring, your form knows to edit that record, otherwise your form adds a new record.
您的添加和编辑表单甚至可以是同一页面,当查询字符串中提供ID时,您的表单知道编辑该记录,否则您的表单会添加新记录。
#3
Have you tried adding the ID in the querystring? Then you could read it, and add it to the session as needed (say on a user clicking the back button).
您是否尝试在查询字符串中添加ID?然后你可以阅读它,并根据需要将它添加到会话中(比如用户点击后退按钮)。
Seems like a lot of problems allowing editing of an object in a page rendered when using the back button. Would it be too much to give them an edit button instead?
看起来很多问题允许在使用后退按钮时编辑页面中的对象。相反,给他们一个编辑按钮会不会太多?
#4
The controls save their state in the ViewState. If you choose to use SessionState instead of ViewState to store the information, then the controls will save their state in the session state and it won't work properly with multiple tabs.
控件将其状态保存在ViewState中。如果您选择使用SessionState而不是ViewState来存储信息,那么控件将在会话状态中保存其状态,并且它将无法与多个选项卡一起正常工作。
I have not yet found a way to bypass this issue while still using SessionState. Our solution was to use the normal ViewState.
我还没有找到一种方法来绕过这个问题,同时仍然使用SessionState。我们的解决方案是使用普通的ViewState。
#5
I've tried storing the ID in the querystring (which is mostly fine for editing), but the problem with that is when the information is stored in session for when they use the Back button. If the user does the following:
我已经尝试将ID存储在查询字符串中(这对于编辑来说非常好),但问题是当信息存储在会话中以便他们使用“后退”按钮时。如果用户执行以下操作:
- User creates a record (1st record), the ID is passed along in the querystring, and temporarily stored in session.
- User creates another record (2nd record), the ID is passed along in the querystring, temporarily stored in session.
- User uses the Back button on the first record to go to the page that doesn't have the querystring.
用户创建记录(第一条记录),ID在查询字符串中传递,并临时存储在会话中。
用户创建另一条记录(第二条记录),ID在查询字符串中传递,临时存储在会话中。
用户使用第一条记录上的“后退”按钮转到没有查询字符串的页面。
It's probably a far-fetched scenario, but it's one that may happen. The only solution I have is to block the usage of the Back button to go back to the adding page, by using window.history.forward() in JavaScript. But this as a solution is terrible.
这可能是一个牵强附会的场景,但它可能会发生。我唯一的解决方案是使用JavaScript中的window.history.forward()阻止使用Back按钮返回添加页面。但这作为解决方案是可怕的。
#6
My question for you is why are you storing anything in the session to begin with? If you can avoid storing anything in the session, I think you will be better off altogether.
我的问题是你为什么要在会话中存储任何内容?如果你可以避免在会话中存储任何东西,我认为你会完全更好。
#7
Having thought about this, does the following sound like a decent solution to the problem I outlined above?
考虑到这一点,以下听起来像是我上面概述的问题的一个体面的解决方案?
- When first adding a record, store a timestamp of when the add page was accessed in a hidden field.
- This timestamp is passed through session when the user clicks save. Along with the ID.
- If the user opens another tab at the same time and saves, then the new page's timestamp gets passed through session.
- If the user tries to access the add page of first record (using the back button), the system looks up session, and sees if there is a timestamp, and whether it matches the one in the hidden field for that page.
- If it doesn't match, then the user gets a prompt, and told to edit the record properly.
首次添加记录时,存储在隐藏字段中访问添加页面的时间戳。
当用户单击“保存”时,此时间戳将通过会话传递。随身份证。
如果用户同时打开另一个选项卡并保存,则新页面的时间戳将通过会话传递。
如果用户尝试访问第一条记录的添加页面(使用后退按钮),系统将查找会话,并查看是否存在时间戳,以及它是否与该页面的隐藏字段中的时间戳匹配。
如果它不匹配,则用户得到提示,并告知要正确编辑记录。
Does this sound reasonable, or too overly complex?
这听起来合理,还是过于复杂?
#1
Silly question, why can the user use the back button to edit the data just accepted in a post?
愚蠢的问题,为什么用户可以使用后退按钮编辑刚刚在帖子中接受的数据?
If the edit previously posted data is a common scenario why not just redirect to a page when the data is accepted that lets them edit it. Then if the hit the back button they would be going back to the original "clean" insert/add new data page.
如果编辑以前发布的数据是一种常见的情况,为什么不只是在接受数据时重定向到页面,让他们编辑它。然后,如果点击后退按钮,他们将返回到原始的“干净”插入/添加新数据页面。
This would give the following flows Add->[Post]->Edit->..... Add->[Post]->Edit->[Back button]->Add->[Post]->Edit->[Post]->Edit....
这将给出以下流程Add - > [Post] - > Edit - > ..... Add - > [Post] - > Edit - > [Back button] - > Add - > [Post] - > Edit-> [发布] - >编辑....
#2
I'd recommend storing your ID in the QueryString. After the record is added, redirect to your "thankyou" page, which then I am guessing contains a link to the edit form which you will generate with the ID in the querystring. When that link is followed, the edit page shouild pull the ID out of the query string in order to load up the correct record to edit.
我建议将您的ID存储在QueryString中。添加记录后,重定向到“thankyou”页面,然后我猜测它包含一个指向编辑表单的链接,您将使用查询字符串中的ID生成该表单。当遵循该链接时,编辑页面应该从查询字符串中提取ID,以便加载要编辑的正确记录。
Your add and edit form can even be the same page, when an ID is provided in the querystring, your form knows to edit that record, otherwise your form adds a new record.
您的添加和编辑表单甚至可以是同一页面,当查询字符串中提供ID时,您的表单知道编辑该记录,否则您的表单会添加新记录。
#3
Have you tried adding the ID in the querystring? Then you could read it, and add it to the session as needed (say on a user clicking the back button).
您是否尝试在查询字符串中添加ID?然后你可以阅读它,并根据需要将它添加到会话中(比如用户点击后退按钮)。
Seems like a lot of problems allowing editing of an object in a page rendered when using the back button. Would it be too much to give them an edit button instead?
看起来很多问题允许在使用后退按钮时编辑页面中的对象。相反,给他们一个编辑按钮会不会太多?
#4
The controls save their state in the ViewState. If you choose to use SessionState instead of ViewState to store the information, then the controls will save their state in the session state and it won't work properly with multiple tabs.
控件将其状态保存在ViewState中。如果您选择使用SessionState而不是ViewState来存储信息,那么控件将在会话状态中保存其状态,并且它将无法与多个选项卡一起正常工作。
I have not yet found a way to bypass this issue while still using SessionState. Our solution was to use the normal ViewState.
我还没有找到一种方法来绕过这个问题,同时仍然使用SessionState。我们的解决方案是使用普通的ViewState。
#5
I've tried storing the ID in the querystring (which is mostly fine for editing), but the problem with that is when the information is stored in session for when they use the Back button. If the user does the following:
我已经尝试将ID存储在查询字符串中(这对于编辑来说非常好),但问题是当信息存储在会话中以便他们使用“后退”按钮时。如果用户执行以下操作:
- User creates a record (1st record), the ID is passed along in the querystring, and temporarily stored in session.
- User creates another record (2nd record), the ID is passed along in the querystring, temporarily stored in session.
- User uses the Back button on the first record to go to the page that doesn't have the querystring.
用户创建记录(第一条记录),ID在查询字符串中传递,并临时存储在会话中。
用户创建另一条记录(第二条记录),ID在查询字符串中传递,临时存储在会话中。
用户使用第一条记录上的“后退”按钮转到没有查询字符串的页面。
It's probably a far-fetched scenario, but it's one that may happen. The only solution I have is to block the usage of the Back button to go back to the adding page, by using window.history.forward() in JavaScript. But this as a solution is terrible.
这可能是一个牵强附会的场景,但它可能会发生。我唯一的解决方案是使用JavaScript中的window.history.forward()阻止使用Back按钮返回添加页面。但这作为解决方案是可怕的。
#6
My question for you is why are you storing anything in the session to begin with? If you can avoid storing anything in the session, I think you will be better off altogether.
我的问题是你为什么要在会话中存储任何内容?如果你可以避免在会话中存储任何东西,我认为你会完全更好。
#7
Having thought about this, does the following sound like a decent solution to the problem I outlined above?
考虑到这一点,以下听起来像是我上面概述的问题的一个体面的解决方案?
- When first adding a record, store a timestamp of when the add page was accessed in a hidden field.
- This timestamp is passed through session when the user clicks save. Along with the ID.
- If the user opens another tab at the same time and saves, then the new page's timestamp gets passed through session.
- If the user tries to access the add page of first record (using the back button), the system looks up session, and sees if there is a timestamp, and whether it matches the one in the hidden field for that page.
- If it doesn't match, then the user gets a prompt, and told to edit the record properly.
首次添加记录时,存储在隐藏字段中访问添加页面的时间戳。
当用户单击“保存”时,此时间戳将通过会话传递。随身份证。
如果用户同时打开另一个选项卡并保存,则新页面的时间戳将通过会话传递。
如果用户尝试访问第一条记录的添加页面(使用后退按钮),系统将查找会话,并查看是否存在时间戳,以及它是否与该页面的隐藏字段中的时间戳匹配。
如果它不匹配,则用户得到提示,并告知要正确编辑记录。
Does this sound reasonable, or too overly complex?
这听起来合理,还是过于复杂?