ASP.net 网站中的导航错误
我使用 Visual Studio 2008 开发了一个网站。它使用活动索引从一个页面导航到下一页。
当用户单击下一步按钮时,它将增加索引。根据增加的值,已导航下一页。
第一页中有一个下拉菜单,其值为(A,B,C,D)。
通常,网站按以下方式导航:
Page1-->page2-->Page1-->page2-->Page1-->page2--> Page3-->Page4 依此类推。
但是,如果 Page1 中的下拉框中的值为“B”,则会导致以下流程。
Page1-->page2-->Page4
但问题是......网站表现得很奇怪。它给出以下流程..
对于下拉选择中的特定值选择(值“B”),Page1-->page2-->Page3-->Page4 而不是 Page1-->page2-->Page4 。
当用户再次转到最后一页时,使用后退按钮回到前面并使用“下一页”按钮转到最后一页,就会发生此问题。 (多次迭代导致此问题)
我在这里需要两件事:
- 为什么会发生?
- 如何防止这种情况
我已经给出了下面的代码:
感谢您提前的帮助,
Protected Sub btn_view1_back_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_view1_back.Click, btn_view2_back.Click, btn_view3_back.Click
Try
Dim currentView As Int16
currentView = mvRequestorForm.ActiveViewIndex
If currentView = 3 And BSelected() = 1 Then
mvRequestorForm.ActiveViewIndex = (currentView - 2)
Else
mvRequestorForm.ActiveViewIndex = (currentView - 1)
End If
If mvRequestorForm.ActiveViewIndex = 1 Then
If (ddl_view0_WULValue() = 0) Then
'C'
CSelected() = 1
strRoleType = "chkBx_C_workunit"
ElseIf (ddl_view0_WULValue() = 1) Then
'head office'
ASelected() = 1
strRoleType = "chkBx_A_workunit"
ElseIf (ddl_view0_WULValue() = 2) Then
'B'
BSelected() = 1
strRoleType = "chkBx_B_workunit"
ElseIf (ddl_view0_WULValue() = 3) Then
'B'
BSelected() = 1
strRoleType = "chkBx_B_workunit"
End If
End If
Catch ex As Exception
End Try
End Sub
下面的“下一步”按钮代码:
Protected Sub btn_View0_Next_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_View0_Next.Click, btn_View1_Next.Click, btn_view2_Next.Click
Try
Dim currentView As Int16
currentView = mvRequestorForm.ActiveViewIndex
If currentView = 1 And BSelected = 1 Then
mvRequestorForm.ActiveViewIndex = (currentView + 2)
rfv_view2_managersEmail.Enabled = True
rev_view2_managersEmail.Enabled = True
Else
mvRequestorForm.ActiveViewIndex = (currentView + 1)
End If
If mvRequestorForm.ActiveViewIndex = 1 Then
Sub_ActivateView1()
End If
Catch ex As Exception
End Try
End Sub
I have developed a website using visual studio 2008. Which uses active index to navigate from one page to the next page.
It will increment the index when the user clicks the next button. According to the incremented value , next pages has been navigated
There is a drop down in the first page with values (A,B,C,D)
Normally, Website navigate in the the following way
Page1-->page2-->Page3-->Page4 and so on..
But if value "B" in a drop down box in Page1 which result in the following flow.
Page1-->page2-->Page4
But the problem is ... Website is acting strange. It gives following flow..
Page1-->page2-->Page3-->Page4 instead of Page1-->page2-->Page4 for that particular value selection (value "B") in drop down selection.
This issue is happening, when user goes to the last page again come to the front using back button and go the last page using “next “button. (Multiple iterations causing this issue)
Two things i need here :
- Why it is occurring?
- How to prevent this
I have given the code below :
Thanks for the help in advance
Protected Sub btn_view1_back_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_view1_back.Click, btn_view2_back.Click, btn_view3_back.Click
Try
Dim currentView As Int16
currentView = mvRequestorForm.ActiveViewIndex
If currentView = 3 And BSelected() = 1 Then
mvRequestorForm.ActiveViewIndex = (currentView - 2)
Else
mvRequestorForm.ActiveViewIndex = (currentView - 1)
End If
If mvRequestorForm.ActiveViewIndex = 1 Then
If (ddl_view0_WULValue() = 0) Then
'C'
CSelected() = 1
strRoleType = "chkBx_C_workunit"
ElseIf (ddl_view0_WULValue() = 1) Then
'head office'
ASelected() = 1
strRoleType = "chkBx_A_workunit"
ElseIf (ddl_view0_WULValue() = 2) Then
'B'
BSelected() = 1
strRoleType = "chkBx_B_workunit"
ElseIf (ddl_view0_WULValue() = 3) Then
'B'
BSelected() = 1
strRoleType = "chkBx_B_workunit"
End If
End If
Catch ex As Exception
End Try
End Sub
Code for Next button below :
Protected Sub btn_View0_Next_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_View0_Next.Click, btn_View1_Next.Click, btn_view2_Next.Click
Try
Dim currentView As Int16
currentView = mvRequestorForm.ActiveViewIndex
If currentView = 1 And BSelected = 1 Then
mvRequestorForm.ActiveViewIndex = (currentView + 2)
rfv_view2_managersEmail.Enabled = True
rev_view2_managersEmail.Enabled = True
Else
mvRequestorForm.ActiveViewIndex = (currentView + 1)
End If
If mvRequestorForm.ActiveViewIndex = 1 Then
Sub_ActivateView1()
End If
Catch ex As Exception
End Try
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您发布 ASelected()、BSelected()、CSelected() 和 ddl_view0_WULValue() 会有更多帮助。如果没有它,我无法真正确定为什么会发生这种情况。我的猜测是因为 Web 应用程序中缺乏状态。当您尝试在页面的代码隐藏中设置变量时,对象仅在该单个回发期间(在本例中为单击按钮)保留在周围。下次单击按钮时,页面私有变量的所有数据都将消失。
但是,下拉列表的状态将在回发之间保持,因此您可以直接查询下拉列表以了解已选择的内容。我将其更改为
ddl_view0.SelectedValue = "B"
,而不是BSelected() = 1
我认为这就是您的 aspx 页面的样子。请注意 ListItem 上 Text 和 Value 属性的使用。我们将使用代码中的 Value 属性来查找所选内容。
我更改了您的代码以消除所有 ASelected()、BSelected、CSelected 和 dll_view0_WULValue() 调用,而直接使用下拉列表。
我不知道 strRoleType 的用途,但这可能也无法正常工作。如果没有,请尝试在窗体上放置一个 HiddenField 控件并使用它来存储值。
If you posted ASelected(), BSelected(), CSelected() and ddl_view0_WULValue() that would have helped more. Without that I can't really determine why it's happening. My guess is because of the lack of state in a web application. When you try to set variables in a page's code behind, objects only stay around during that single postback (in this case, a button click). The next time a button click happens, all of that data your page's private variables will be gone.
However, the state of the drop down list will be maintained between postbacks, so you can query the drop down list directly to find out what's been selected. Instead of
BSelected() = 1
, I've changed it toddl_view0.SelectedValue = "B"
I assumed that this is what your aspx page looked like. Notice the use of Text and Value properties on the ListItem. We'll use the Value property in the code to find what is selected.
I've changed your code to get rid of all of the ASelected(), BSelected, CSelected, and dll_view0_WULValue() calls and just use the drop down list directly.
I don't know what strRoleType is for, but that probably won't work correctly either. If it doesn't, try dropping a HiddenField control on your form and use that to store the value.