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

dropdownlist not retaing value

Status
Not open for further replies.

rotsey

Programmer
Nov 23, 2004
135
AU
HI,

I have a dropdownlist on a page that is not retaining its value on postback. i have other controls on the page that are.

I have some javascript in the page but cannot see that I am doing any thing to it.

Anyone have any ideas??
rotsey
 
Is it being bound on PostBack?

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
yes it is. Looking at the source on postback there are values in it.
 
Well if it's being bound on PostBack then it will not retain the value that the user selected (as it is being bound again the first item will be selected).

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
well it works on another dropdownlist on the same page.

I am creating a large table with lots of rows and cells so I am using code to load a table control. so to get it to build my table on postback I have to call the load function each time like this.

Code:
   Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     BuildTable()
     If not IsPostback Then
        'do what ever
     End if

   End Sub

It is in BuildTable that the dropdownlists get created and filled. On local machine they retain values on postback.

It is only now I have uploaded to the web host that I have a problem with this combo.

rotsey
 
Well if the DropDownList gets called in BuildTable then it will get bound everytime the page is loaded (including postbacks) which means it will get reset each time.

I would suggest seperating the DropDownList bind into another function and only calling it when it is not a postback.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
what you say makes sense but why does it work on other controls and the same control works on my local server??
 
I really don't know. Binding a control on every load should mean that the viewstate from the previous page is overwritten.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
hmmmm.

btw ca8msm I get a javascript debug message box when I load pages am on this site. I have IE 6.0.


Do you get that??
 
No I don't - I have FireFox and IE6.

What are the javascript errors?

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
It seems just this page

Line 17
Error Expected ';'


Anyhow thanks for the dropdownlist fix. Works well now.
 
No probs.

I can't replicate the error here. If it keeps occuring you can log it with management using the Contact Us link in the top right hand corner of the page.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top