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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdownlist vs. button 1

Status
Not open for further replies.

Compkitty

Programmer
Jan 7, 2005
121
US
I have one dropdownlist, 2 buttons.. the DDL is on autopostack (so that when a user selects an item; that item is saved as a variable then they are redirected to another page) however, when they go back (ie. backbutton) and try to click one of the buttons they still go to the previous page, not thep age for the button..

ie.
button1 goes to page1
button2 goes to page2
Dropdownlist goes to page3

User selects item in dropdown and goes to page3, but doesn't find the info, so hits the backbutton to go to mainpage to use the buttons. User then selects Button1 and is directed to page3, but should go to page1....

What's my issues???
 
I believe this is because of the way session or view state works in asp.net, and therefore it is by design.

Could you post your code so we can make sure this is the issue and not a program error of some sort?

Thanks.
 
Here's the code

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
     

        If Not Page.IsPostBack Then

            Me.DaCName.Fill(DsCName)
            Me.DdlCname.DataSource = DsCName
            DdlCname.DataTextField = "NameonRpt"
            DdlCname.DataValueField = "ID"
            DdlCname.DataBind()

        End If

    End Sub

    Public Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click

        Response.Redirect("StpAddID.aspx")

    End Sub

    Private Sub BtnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFind.Click

        Response.Redirect("StpIdList.aspx")

    End Sub

    Private Sub DdlCname_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DdlCname.SelectedIndexChanged
        Me.txtValue.Text = Me.DdlCname.SelectedValue.ToString
        Session("Id") = Me.txtValue.Text
        Response.Redirect("StpIdList.aspx")
    End Sub

End Class

 
It looks like you are redirecting to

StpIdList.aspx

in 2 places.

Let me know if this isn't correct.
 
is there a reason why one button click is Public and one is Private?

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
1. public/private.. I was trying to fix the issues, didnt' change it back

2. the second redirect to that page, is there just for now...

 
I was able to recreate your problem. I still believe this is by design. I will try some other things and will get back to you if I have success.
 
Ok this is a possible solution.

Make a jpeg of the buttons you want, and then put a hyperlink control around them. This will not cause any event to occur and therefore will not go back to the page that the dropdown list was directing it to. Link Button does not work, only the hyperlink.
 
Henslecd, why do you think this is by design? I'm getting interested now...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
In this case, I don't think it is something they did that made it better, but I believe that they designed it so you can use the back button and then come forward again without losing data. This is helpful for those who fill out forms, then go back, and then want to go forward again. This is an opinion of course as I don't work at Microsoft and am hardly a .Net expert. I would like to really learn how everything works behind the scenes, so questions like these are easily solved by saying, sorry can't do it, here is the work around...
 
Also note that when you hit back the dropdownlist that you selected holds the viewstate of the selected item. So basically what they did was keep all the dropdowns from having to be selected all over again. Which is a plus in some cases, but obviously not in this one.
 
Thanks for all ur assistance, I will try these and see what flies..
 
P.S. I did do the workaround w/ using an image and a Hyperlink... Works GREAT!!! THANKS henslecd!!!
 
Ok, I've found a snag.... I have used a hyperlink w/ the image.. but what if that button had a command under it?? ie. an onclick event...
 
Then you can't do it. Try using the original code but put this in the page load.

Code:
Response.Buffer = True  
Response.ExpiresAbsolute = Now().Subtract(New TimeSpan(1, 0, 0, 0)) 
Response.Expires = 0 
Response.CacheControl = "no-cache"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top