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@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Britain Crooker" <britainc@community.nospam>
>Subject: asp:DropDownList and Javascript
>Date: Wed, 19 Mar 2008 21:53:09 -0400
>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 the
[quoted text clipped - 10 lines]
>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".
Britain Crooker - 20 Mar 2008 15:31 GMT
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?
> Hi Britain,
>
[quoted text clipped - 64 lines]
>>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".
Britain Crooker - 20 Mar 2008 16:15 GMT
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.
> Would it also be acceptable to update the first dropdown
> AutoPostBack=TRUE, then put in the SelectedIndexChanged event the code to
[quoted text clipped - 72 lines]
>>>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".
Steven Cheng - 21 Mar 2008 02:31 GMT
Thanks for your reply Britain,
Sure, you can use the "SelectedIndexChanged" event of the first
dropdownlist to change the second(child) one's items. I didn't mention this
means in previous message because I assume that you may want a non-postback
approach(that will not refresh page).
As for the new question you mentioned, I'm afraid Javascript is necessary
here for you to provide additional information (whch control/elemente
trigger the submit postback....). A plain html form submit will not contain
any information about the source control who raise the postback/submit. Is
there any particular requirement on client-side that can not use javascript?
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@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>Subject: Re: asp:DropDownList and Javascript
>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
[quoted text clipped - 84 lines]
>>>>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".
Steven Cheng - 25 Mar 2008 09:48 GMT
Hi Britain,
Have you got any progress on this issue? I'm still monitoring this thread
and welcome to post here if there is anything else we can help.\
Sincerely,
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@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: stcheng@online.microsoft.com ("Steven Cheng")
>Organization: Microsoft
>Date: Fri, 21 Mar 2008 01:31:05 GMT
>Subject: Re: asp:DropDownList and Javascript
>Thanks for your reply Britain,
>
[quoted text clipped - 78 lines]
>>>>
>>>> #UpdatePanel Control Overview
http://asp.net/ajax/documentation/live/overview/UpdatePanelOverview.aspx
>>>> Best regards,
>>>>
[quoted text clipped - 39 lines]
>>>>>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".