我正在构建一个带有vb.net代码的asp.net网页。
我的网页旨在当用户点击按钮而不填写相关文本框时显示错误;下面的代码显示了它的工作原理:
If txtOrderNumber.Text = "" Then
lblStatus.Text = orderNoWarning
lblStatus.CssClass = "error"
ElseIf txtPhaseNumber.Text = "" Then
lblStatus.Text = phaseNoWarning
lblStatus.CssClass = "error"
ElseIf txtOrderNumber.Text.Length > 0 AndAlso txtPhaseNumber.Text.Length > 0 Then
Try
Dim intOrderNumber As Integer = CInt(txtOrderNumber.Text)
Try
Dim intPhaseNumber As Integer = CInt(txtPhaseNumber.Text)
Dim objWIP_Tracking As New wsWIP_Tracking.WIP_TrackingSoapClient
Dim myResults As wsWIP_Tracking.TicketType2 = objWIP_Tracking.GetTicketType2(intOrderNumber, intPhaseNumber)
If myResults = wsWIP_Tracking.TicketType2.AME Or _
myResults = wsWIP_Tracking.TicketType2.Orion Then
lblStatus.Text = ""
Response.Redirect("http://ligrptsvr2/default.aspx?Report=JoinerySummarybyComponent.rpt&username=imservices&FOLDER=Analytics&OrderNo=" & intOrderNumber.ToString & "&PhaseNo=" & intPhaseNumber.ToString & "&ParameterPrompt=yes")
ElseIf myResults = wsWIP_Tracking.TicketType2.GS Then
lblStatus.Text = ""
Response.Redirect("http://ligrptsvr2/default.aspx?Report=JoinerySummary_GreenScreen.rpt&username=wip&FOLDER=Analytics&JobNo=" & intOrderNumber.ToString & "&PhaseNo=" & intPhaseNumber.ToString & "&ParameterPrompt=yes")
ElseIf myResults <> wsWIP_Tracking.TicketType2.AME Or _
myResults <> wsWIP_Tracking.TicketType2.Orion Or _
myResults = wsWIP_Tracking.TicketType2.GS Then
lblStatus.Text = warning
lblStatus.CssClass = "warning"
Else
Response.End()
End If
Catch ex As Exception
End Try
Catch ex As Exception
End Try
Else
lblStatus.Text = ""
End If
但是,当response.redirect(重定向到新页面)发生时,我想清除标签(lblstatus)。代码'lblstatus.text =“”'不起作用。当用户被重定向到新页面然后返回(使用浏览器后退按钮)时,标签仍然显示错误。我试过禁用和启用viewstate;没有任何区别。我该怎么做才能清除这个标签?
答案 0 :(得分:0)
请参阅:What happens when I press browser BACK button?
当您在浏览器中按下后退按钮时,大多数浏览器只会在重定向发生之前以最新状态显示html页面的缓存副本。该功能完全取决于浏览器。因此,您的VB代码或视图状态几乎无法执行任何操作。
一个选项是在页面加载时使用java-script来动态切换错误信息(这就是我遇到这种问题时所做的事情)。