SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Spain
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Basic Postback Question

    Good evening, apologies for the apparent simpleness of my 'problem', i'm quite new to coding in .net and I think its confusing me a little.

    I have a page with a gridview and a dropdown (postback) box listing the dates available to filter the grid by with the newest first.

    However i'd also like the user to be able to 'jump' to the page by using a query string so they dont have to go to the page and then filter ie

    http://localhost/view.aspx?date=01/04/2008

    They can then use the dropdown to select a different date should they need to.

    Pretty simple so far and i've managed to get the above working with the below in pageload

    Code:
    If Not IsPostBack Then
    
    
                If IsDate(Request.QueryString("date")) Then
                    If DropDownList1.Items.FindByText(Request.QueryString("date")) Is Nothing Then
                        DropDownList1.Items.Add(New ListItem(Request.QueryString("date"), Request.QueryString("date")))
                    End If
    
                    DropDownList1.SelectedValue = Request.QueryString("date")
                Else
                    DropDownList1.SelectedIndex = 0
                End If
    
            End If

    My question is really should I be using postback in the dropdown if im using a querystring? Theres something that doesn't sit right with me showing the date in the url but showing a different dates data in my page

    Should I drop the postback and stick with loading the new url when the dropdown changes and solely use the querystring? i'd just use the newest date if the date querystring was invalid or missing.

    It there anything wrong with the current solution and will I lose functionality not using postback on the dropdown? It just doesn't seem very graceful.

    I've walked away and made a cup of tea and I still can't get my head around what should be an easy thing to solve (me being too fussy I guess)

    Thanks for any pointers.

  2. #2
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are not being too fuzzy. And this problem is by no means simple. For all of its virtues, this is one area where ASP.NET has managed to seriously confuse the concepts. I will certainly agree that having one date in the url and another at the page is a smell.

    You should always show the page according to the url. You can fix this in two ways: 1) After postback do a Response.Redirect with the posted parameter in the url or 2) drop the webcontrol/webform in this case.

    The latter would involve creating a form without the runat="server" attribute outside the webform (if you need any). In this form use a standard html select tag instead of the dropdownlist webcontrol. If you put a runat="server" on the select tag you can still populate it from codebehind very much like the dropdownlist.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Spain
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for the reply, I googled around and didn't find any alternatives or 'hacks'. I did look into adding a button and use the postbackurl, but then I guess by that time it reached the server it has already decided the destination?

    I guess this link highlights a simplified version of my problem.

    Response.Redirect seems to work fine, if not a little "old skool"... what do I lose by using the redirect instead of the postback?

    Alternatively I could either let it ride with the querystring not necessarily matching the page...

    Or if the date is supplied in the address could I redirect to plain url which jumps to the date through postback done perhaps on code ay page load (is that possible?) and then use postback to change the dropdown as above?, with perhaps a 'track back' url listed on the page?

    It depends what dropping the postback loses me... can anyone clarify?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •