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

Show Dropdownlist Without PostBack 1

Status
Not open for further replies.

jonbatts

Programmer
Apr 12, 2005
114
US
Alright, I've got an application with Items and SubItems (generic names). I want a user to be able to be able to select an Item in a dropdownlist, which then without posting back gives them an option to select a SubItem from another dropdownlist. To this point I've been filling the Item dropdownlist, dynamically creating a dropdownlist for each Item and filling it with SubItems, and using Javascript to show only the SubItem dropdownlist which contains SubItems for the currently selected Item. This works fine, accept for the fact that due to the nature of the application and my inability to create my dynamic controls in the OnInit I'm having to recreate my dropdownlists without viewstate in the PageLoad. The only problem with this is if the user navigates to another page and comes back via a Done button, the incorrect SubItem dropdownlist is shown. Here's the .NET code which adds the JavaScript to the window.onload.
Code:
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "windowLoad", strScriptHeader + strShowLabel + strHideDDLs + strShowSubItem + strScriptFooter);
What's really interesting is when I step through the code strShowSubItem (which shows the SubItem) says that it will show the correct SubItem dropdownlist, but when I look at the source of the page, it shows the dropdownlist of the last Item I was setting.
What I'm really looking for is a way to do this differently. Someone was telling me about using XML to do this but I haven't been able to find a way to do that. If anyone has any ideas, I would greatly appreciate it.
 
I want a user to be able to be able to select an Item in a dropdownlist, which then without posting back gives them an option to select a SubItem from another dropdownlist.
Without going into what you have already done, there are two ways you can accomplish this in ASP.NET without a postback. They are:

1) Javascript
2) AJAX

The first one will involve loading all the subitems into a javascrip array and only showing whichever ones correspond to the "parent" item.

The second one will involve creating the sub items based on what the user selects in the parent (and it will use the SelectedIndexChanged event of the "parent" DropDownList). If you go with this route, check out the ATLAS documentation.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I don't understand what you're referencing when you say "a Javascript array". Can I fill an HTML Select (dropdownlist) with all the SubItems and show only the necessary ones? Is there JavaScript syntax which shows/hides Options in an HTML Select? How would this be implemented otherwise? If I went w/one ddl showing and hiding the correct Options instead of dynamically creating a ddl for each SubItem this would make things much simpler. Thanks a lot.
 
Can I fill an HTML Select (dropdownlist) with all the SubItems and show only the necessary ones? Is there JavaScript syntax which shows/hides Options in an HTML Select?
Yes you can. A quick google search came up with this example although there are many others:



____________________________________________________________

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