1

I'm building an asp.net web page with vb.net code behind.

My web page is designed to display an error when the user clicks a button without filling the relevant textbox; the code below shows how this works:

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

However, when a response.redirect (redirects to new page) occurs , I would like to clear the label(lblstatus). The code 'lblstatus.text=""' does not work. When the user gets redirected to a new page then goes back (using browser back button), the label still shows an error. Iv tried disabling and enabling viewstate; doesn't make any difference. What can I do to clear this label?

Sabelo Ngcobo
  • 33
  • 1
  • 7
  • _"displays an error"_ if you want us to fix it you should mention _what_ kind of error – Tim Schmelter Feb 18 '15 at 09:19
  • He has a problem with his data validation. – Amen Jlili Feb 18 '15 at 09:20
  • If the user clicks on the back button the browser will use it's cache to display the HTML. Let the user see again what he has already seen, that is what he expects and wants. – Tim Schmelter Feb 18 '15 at 09:21
  • There are no 'errors' .. as JLILI Aman states; its a validation issue. All I want to do is essentially clear 'lblstatus' after redirecting to a new page. – Sabelo Ngcobo Feb 18 '15 at 09:25
  • @TimSchmelter I get the logic in what your saying. However, when the user is redirected to a new page; the 'error' that was displayed before should no longer applicable (as they have successfully been redirected) therefore should be cleared – Sabelo Ngcobo Feb 18 '15 at 09:33
  • @SabeloNgcobo http://demos.telerik.com/aspnet-mvc/maskedtextbox/validation – Amen Jlili Feb 18 '15 at 09:50

1 Answers1

0

Please see: What happens when I press browser BACK button?

When you press back button in a browser, most browsers will just display the cached copy of the html page in it's latest state, before the redirect happened. The functionality is totally browser dependent. Hence, your VB code or viewstate can hardly do anything.

One option is to use java-script on page load, to dynamically toggle the error message (which is what I do when I have this kind of a problem).

Community
  • 1
  • 1
Ganesh Jadhav
  • 2,830
  • 1
  • 20
  • 32