Re: asp:DropDownList and Javascript
- From: "Britain Crooker" <britainc@xxxxxxxxxxxxxxxx>
- Date: Thu, 20 Mar 2008 11:15:33 -0400
Ok, what I described below MOSTLY seems to work, with one issue. If I
disable JavaScript in my browser, then (obviously) the SelectedIndexChanged
event will not fire until the user actually clicks the Submit button, rather
than firing immediately after a new selection is made.
Is there any way to determine which control initiated the PostBack?
Basically, I would want the SelectedIndexChange event to not fire (or exit
immediately) if the Submit button was pressed.
I have found some sample code for determining the PostBox control, but they
are all dependent on JavaScript.
"Britain Crooker" <britainc@xxxxxxxxxxxxxxxx> wrote in message
news:uO3kScpiIHA.5208@xxxxxxxxxxxxxxxxxxxxxxx
Would it also be acceptable to update the first dropdown
AutoPostBack=TRUE, then put in the SelectedIndexChanged event the code to
update the dropdown items for the second control?
""Steven Cheng"" <stcheng@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:kMK0KXliIHA.360@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi Britain,
From your description, you use javascritp to add some items into an
ASP.NET
dropdownlist, however, you found those added items disappear after the
page
be postback, correct?
I think this is the expected behavior due to ASP.NET webserver control's
control model. The control will construct its inner structure(and set
properites) at server-side, all those status will be persited in
Viewstate
and render to client html. yes, you can modify the client-side html
elements, however, after you postback the page, the page will recreate
the
control structure from viewstate, and your change at client-side will be
lost.
For your scenario, I think you can consider the following means:
1. You can consider add a hidden html field in page and add those items
(you add into dropdownlist via script) into that field, and after
postback,
always checks this field and syncrhonize those items in the field to your
dropdownlist's server-side item collection
2. You can consider use the ASP.NET ajax control (such as updatepanel) to
provide postback processing without refreshing the page:
#UpdatePanel Control Overview
http://asp.net/ajax/documentation/live/overview/UpdatePanelOverview.aspx
Best regards,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you.
Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx
This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
From: "Britain Crooker" <britainc@xxxxxxxxxxxxxxxx>
Subject: asp:DropDownList and Javascript
Date: Wed, 19 Mar 2008 21:53:09 -0400
the
First - my MSDN Posting Alias isn't defined yet because the MSDN site is
having problems, it came back with " We were unable to communicate with
Managed Newsgroups registration system".the
I have an ASP.NET website using C#. One page has two asp:DropDownList
controls, one that controls the other. Think a car website (first select
make, then model). I am using Javascript to populate the second list as
first one changes. The problem is that when I query these controls afterthe
the Submit button is pressed, it always returns back the first value of
original list contents of the second control. It seems to be ignoringwhat
the Javascript did during runtime. So if the original list had "1", "2"and
"3" in the list, and then the user changes list 1 to another option,
which
updates list 2 to have "4", "5" and "6" in the list. If the user clicks
submit and the code queries the value of list 2, it will return "1".
.
- Follow-Ups:
- Re: asp:DropDownList and Javascript
- From: "Steven Cheng"
- Re: asp:DropDownList and Javascript
- References:
- asp:DropDownList and Javascript
- From: Britain Crooker
- RE: asp:DropDownList and Javascript
- From: "Steven Cheng"
- Re: asp:DropDownList and Javascript
- From: Britain Crooker
- asp:DropDownList and Javascript
- Prev by Date: Re: Managing TODOs in your source code
- Next by Date: Creating a User Control
- Previous by thread: Re: asp:DropDownList and Javascript
- Next by thread: Re: asp:DropDownList and Javascript
- Index(es):
Relevant Pages
|