• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

ASP.NET help

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.
 
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.
 
are you re-binding the subtype dropdown list in page_load before your code has a chance to read what the user selected?
 
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 🙂 )
 
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
 
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.
 
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.
 
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.
 
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
 
Back
Top