Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to go back to a search results page

Status
Not open for further replies.

JulesBos

Programmer
Sep 6, 2006
68
US
Hi,

I've got a search results page that takes information from its query string and displays data in labels and a datagrid. It works well, until you move to a new page then go back to it. When you go back there's an error message.

The current code (first part) is:

Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        dateFrom = Request.QueryString("DateFrom")
        dateTo = Request.QueryString("DateTo")
        quoteID = CInt(Request.QueryString("QuoteID"))
        quoteNo = Request.QueryString("QuoteNo")
        customerID = CInt(Request.QueryString("CustID"))
        customerName = Request.QueryString("CustName")
        partNo = Request.QueryString("PN")
        raiserID = Request.QueryString("RaiserID")
        raiserName = Request.QueryString("RaiserName")
        lifecycle = Request.QueryString("Lifecycle")
        breakdown = Request.QueryString("Breakdown")
        all = Request.QueryString("All")

        If Not Me.IsPostBack Then
           'find out what type of user the person is and set the page up as required
            'first instance if the user has no permissions then redirect them
            Select Case Global.WindowsUser.Level
                Case UserPermissionLevel.None
                    Response.BufferOutput = True
                    Response.Redirect("PermissionsErrors.aspx?ErrorType=NoPermissions")
                'otherwise populate the form
                Case UserPermissionLevel.Read, UserPermissionLevel.Edit, UserPermissionLevel.DataAdmin, UserPermissionLevel.SystemAdmin
                    Me.QuoteSearchDataAdapter.SelectCommand.Connection = Connection
                    Me.DBCommand.Connection = Connection
                    'Get all the information needed for the search from the query string
                    'and populate the search criteria labels for the user
                    dateFrom = dateFrom.Remove(0, 1)
                    If dateFrom <> "00/00/00" Then
                        Dim Day As String = Right(dateFrom, 2)
                        Dim Month As String = Mid(dateFrom, 6, 2)
                        Dim Year As String = Left(dateFrom, 4)
                        dateFromDate = ConvertToDateString(Year, Month, Day)
                        dateFrom = GetEnglishDateString(dateFrom)
                        Me.DateFromLabel.Text = dateFrom
                    Else
                        Me.DateFromLabel.Text = "N/A"
                    End If
                    If dateTo <> "00/00/00" Then
                        Dim Day As String = Right(dateTo, 2)
                        Dim Month As String = Mid(dateTo, 6, 2)
                        Dim Year As String = Left(dateTo, 4)
                        dateToDate = ConvertToDateString(Year, Month, Day)
                        dateTo = GetEnglishDateString(dateTo)
                        Me.DateToLabel.Text = dateTo
                    Else
                        Me.DateToLabel.Text = "N/A"
                    End If

The place where I'm getting an error is:

dateFrom = dateFrom.Remove(0, 1)
The error is "Index and Count must refer to a location within the string. Parameter name = count."

Any ideas why this should work first time, but not on post back? The query string is still the same.

Julia
 
Sorry should have checked. The query string looks the same, but the variables aren't being populated on a post back.

How do I get around that one then?

Julia
 
You will have to debug your code and find out why they are not populating the way you expect
 
I'm a bit stuck here. I've debugged and in code on postback the variable dateFrom's value is "" as is the Request.QueryString("DateFrom") value. However, when looking at the query string in the address bar the value is "#00/00/00".

I don't know how to debug further or where to look?

I'm fairly new to asp.Net and am not very familiar with postbacks etc.

Thanks in advance.
Julia
 
Sorry should have said in the previous post - I'm also confused as to why the code is even being run because it starts with:

If Not Me.IsPostBack Then

surely, as this IS a postback, then the code should be skipped? Or am I not understanding postbacks properly?

Julia
 
A Postback is when a control on the page posts back to the parent page it is contained by.

So if you are navigating to this page from a link, back button etc then the page isnt posting back to it'sself, so the statement above is true and the code will execute.

Request.QueryString() will return a string. So if your variable dtDateFrom is a DateTime, then you need to parse / Convert the string into a valid date time - CDate(dateString) I think. However, if you cannot garuantee that dateString will always be in the querystring, then consider how you will handle the case of it being 'nothing'

hth

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top