DropDown question

J

Jon

I am using cascading dropdowns, where the selection in one determines what
fills another. In regular ASP I simply loaded a giant dataset into
javascript array and when you clicked on one dropdown, it populated the
others accordingly.

In ASP.Net, I was looking for a way to do this without javascript. So, I
made my form and put code in the SelectedIndexChanged event of the dropdown
that populates the next dropdown. Of course to do this, you have to submit
the form. Is there a way of determining when the form has been truly
submitted and when it's been submitted simply to fill in the next dropdown?
I'm thinking not, but thought I'd ask before I revert to my javascript
method.

Thanks
 
M

MattC

Jon,

Try not to think of the the form as being trully submitted or not. In
essence to get anything done in ASP.NET you must postback, what determines
what happens is what causes the postback. In your case:

the SelectedIndexChanged event of dropdown one, will cause you to get the
value of the selected item and populate dropdown two based on that value.

Somewhere at the bottom you mayhave a button on the Click event you may then
look at the values of the selected items in dropdown lists one and two and
then perform some action.

The need for you to determine when the form has been 'trully' submitted is
done for you by means of which events are fired, if the button is click you
then know they want to submit their selections.

MattC
 
G

Guest

If you set the AutoPostBack property of each dropdown list to True, it will
trigger the SelectedIndexChanged event as a postback (where you can load up
the next dropdown lists contents). You can handle the change event in there
and handle form submission (as a whole) in some other event.

Of course, all those postbacks can take their toll on a widely-used
application.
 
B

Ben Strackany

Yep, Matt is right. Jon, you can think of it like a VB6 form, where each UI
element can fire it's own method when clicked.

So in asp.net, in the UI you'd have e.g.

<asp:button runat="server" text="Click Me" onclick="mybutton_click" />

and in your code behind you'd have

Sub mybutton_click(Sender as Object, E as EventArgs)
' do something
end sub

So when the user clicks the "Click Me" button on the web page, the
"mybutton_click" function gets executed. You don't have to worry so much
anymore about "truly posted" etc. Just make your UI elements & assign their
actions (onchange, onclick, etc.) to functions, and then code the functions.

For a number of ASP.NET pages, the only time you even care when it's posted
is when you want to initialize some values. And you usually do that in the
Page_Load method with some code like

if not (IsPostBack)
' do some initialization code here that only happens when the user first
hits the page
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top