ASP.NET help

Feldenak

Lifer
Jan 31, 2003
14,090
2
81
I have a form that uses a couple of dropdownlists where one is dependent on the other. The user selects a type of equipment and is then presented with a list of subtypes in that category. I'm running into a problem when inserting that record into my db. In some of the subtypes, it doesn't matter what the user chooses, the record inserted into the db is always the first subtype listed.

For example if I'm trying to add a piece of network equipment (Type: Network) and choose the SubType Power Injector, the record inserted into the DB contains the subtype "Switch", which is the first SubType listed on the DDL.
 

InYourFace

Junior Member
Mar 30, 2006
4
0
61
I'm not sure if you are populating the dropdownlists with the subtypes in the code-behind or javascript, I would guess in code-behind. Make sure the EnableViewState of the 1st dropdownlist(Type of equipment) is set to true, so that when you do a postback, it's value is returned to the server.
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
are you re-binding the subtype dropdown list in page_load before your code has a chance to read what the user selected?
 

Feldenak

Lifer
Jan 31, 2003
14,090
2
81
Originally posted by: oog
are you re-binding the subtype dropdown list in page_load before your code has a chance to read what the user selected?

I don't think so. I'll double check when I get back to work (lunch break :) )
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
Originally posted by: oog
are you re-binding the subtype dropdown list in page_load before your code has a chance to read what the user selected?

This is correct- you need to do:
If Not IsPostBack then
<bind>
End if
 

Feldenak

Lifer
Jan 31, 2003
14,090
2
81
Originally posted by: WannaFly
Originally posted by: oog
are you re-binding the subtype dropdown list in page_load before your code has a chance to read what the user selected?

This is correct- you need to do:
If Not IsPostBack then
<bind>
End if

The only databinding I'm doing during Page_Load is in the primary ddl. The subtype ddl doesn't populate until a primary type is selected. The subtype ddl populates correctly, it's just not inserting the selected subtype (always takes the first sub listed) into the db.
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
how is the subtype ddl being populated? is it in an onchange event for the primary type?
 

Feldenak

Lifer
Jan 31, 2003
14,090
2
81
Originally posted by: oog
how is the subtype ddl being populated? is it in an onchange event for the primary type?


Yeah. When the primary type is changed, the form hits the db and populates the subtype ddl for items associated with that type.
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
If you reload the primary type on page load, it's going to muck things up. Make sure you only load initial data if the page is not posted back.
 

Stuxnet

Diamond Member
Jun 16, 2005
8,392
1
0
Originally posted by: Feldenak
Originally posted by: WannaFly
Originally posted by: oog
are you re-binding the subtype dropdown list in page_load before your code has a chance to read what the user selected?

This is correct- you need to do:
If Not IsPostBack then
<bind>
End if

The only databinding I'm doing during Page_Load is in the primary ddl. The subtype ddl doesn't populate until a primary type is selected. The subtype ddl populates correctly, it's just not inserting the selected subtype (always takes the first sub listed) into the db.

If you bind it every postback, you're going to run into things like this.

Like someone else said:

If Not IsPostBack Then
databinding and other resource-intensive stuff...
End If