How to append DropDownList value to button's PostBackUrl?

Discussion in 'ASP .Net' started by rob, Mar 20, 2008.

  1. rob

    rob Guest

    Hi,

    I have a button whose PostBackUrl should include a value from a dropdownlist
    on the same page. Should I do that in the button's on click event? What
    I'd like to end up with is a post back url that looks like the following:
    PostBackUrl=somepage.aspx?param=<value> where <value> comes from the
    currently selected item in the list.

    Thanks,
    Rob
     
    rob, Mar 20, 2008
    #1
    1. Advertisements

  2. rob

    David Wier Guest

    The problem with setting the PostbackURL when you click the button, is that
    postback is already beginning.
    What you'd probably want to do is set up a variable for the selected item,
    with a page scope

    Then, when the DDL is changed (using the OnSelectedIndexChanged event),
    assign the selected item to the variable - and THEN, set the Postback url,
    using the variable (PostBackUrl="somepage.aspx?param=" & myVariable)

    Then, when you click the button, it should go there - the problem would then
    be whether or not something is actually selected, so you would probably need
    to do validation

    Or you could just use a response.redirect statement
    (response.redirect(="somepage.aspx?param=" & myVariable) within the button's
    click event handler

    David Wier
    http://aspnet101.com
    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup


    "rob" <> wrote in message
    news:%...
    > Hi,
    >
    > I have a button whose PostBackUrl should include a value from a
    > dropdownlist on the same page. Should I do that in the button's on click
    > event? What I'd like to end up with is a post back url that looks like
    > the following:
    > PostBackUrl=somepage.aspx?param=<value> where <value> comes from the
    > currently selected item in the list.
    >
    > Thanks,
    > Rob
    >
     
    David Wier, Mar 20, 2008
    #2
    1. Advertisements

  3. rob

    Teemu Keiski Guest

    Hi,

    this does not reply 100% exactly what you asked for but in my post

    ASP.NET: trigger cross-page postback on ListBox selection change
    http://aspadvice.com/blogs/joteke/a...age-postback-on-ListBox-selection-change.aspx

    I demonstrate how to use PostBackUrl type of stuff (=cross-page postback)
    so that the value is accessible via PreviousPage

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net



    "rob" <> wrote in message
    news:%...
    > Hi,
    >
    > I have a button whose PostBackUrl should include a value from a
    > dropdownlist on the same page. Should I do that in the button's on click
    > event? What I'd like to end up with is a post back url that looks like
    > the following:
    > PostBackUrl=somepage.aspx?param=<value> where <value> comes from the
    > currently selected item in the list.
    >
    > Thanks,
    > Rob
    >
     
    Teemu Keiski, Mar 20, 2008
    #3
  4. rob

    Teemu Keiski Guest

    Forgot to say, it should also work for DropDownList just as well as for
    ListBox.


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net


    "Teemu Keiski" <> wrote in message
    news:...
    > Hi,
    >
    > this does not reply 100% exactly what you asked for but in my post
    >
    > ASP.NET: trigger cross-page postback on ListBox selection change
    > http://aspadvice.com/blogs/joteke/a...age-postback-on-ListBox-selection-change.aspx
    >
    > I demonstrate how to use PostBackUrl type of stuff (=cross-page postback)
    > so that the value is accessible via PreviousPage
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    >
    >
    > "rob" <> wrote in message
    > news:%...
    >> Hi,
    >>
    >> I have a button whose PostBackUrl should include a value from a
    >> dropdownlist on the same page. Should I do that in the button's on click
    >> event? What I'd like to end up with is a post back url that looks like
    >> the following:
    >> PostBackUrl=somepage.aspx?param=<value> where <value> comes from the
    >> currently selected item in the list.
    >>
    >> Thanks,
    >> Rob
    >>

    >
    >
     
    Teemu Keiski, Mar 20, 2008
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HYRY
    Replies:
    10
    Views:
    820
    Bruno Desthuilliers
    Sep 26, 2007
  2. Fabio Mastria
    Replies:
    2
    Views:
    2,780
  3. Andy B
    Replies:
    3
    Views:
    639
    Eliyahu Goldin
    Sep 8, 2008
  4. Pat

    Append a new value to dict

    Pat, Oct 13, 2008, in forum: Python
    Replies:
    19
    Views:
    23,072
    kljuka
    Nov 17, 2010
  5. micropentium
    Replies:
    8
    Views:
    3,507
    micropentium
    Jan 28, 2010
  6. Hiten
    Replies:
    1
    Views:
    932
    Vidar Petursson
    May 26, 2004
  7. Martin Sharon

    append .cvs behind an array value

    Martin Sharon, Apr 27, 2009, in forum: Ruby
    Replies:
    4
    Views:
    164
    Martin Sharon
    Apr 27, 2009
  8. pt36
    Replies:
    9
    Views:
    766
    Thomas 'PointedEars' Lahn
    Jul 13, 2008
Loading...