Thanks for Jim's informative input.
Hi MC,
For the two issues you mentioned, they're due to the following things:
1. The ASP.NET Webcontrol's state is stored in ViewState by default and it
is a compressed and encoded format which can not be modified at
client-side. Thus, any change to the webcontrol's state(except those
property that will be postback every time such as TextBox's Text or List's
selectedItem) at client-side will not be automatically post to server-side.
2. For the EventValidation problem, this is due to the new event validation
in ASP.NET 2.0(by default enabled), it will ensure that all the postback on
the page are raised by the built-in postback script generated by the page
or any webcontrol rather than other custom code(directly injected scripts).
For example, if you use Response.Write to output some postback scripts,
it will violate the event validation.
For the two issues, you can consider the following means to work them out:
1) As Jim suggested, you can use an html input hidden field(<input
type="hidden" .../>) in the page and at client-side, whenever the
dropdownlist has been changed(add or remove items), you update the hidden
field so as to persist the changes. After the page postback, you can check
the hidden field's value and synchorize the status into DropDownlist's
server control instance.
2) If disable EventValidation is doable, you can just turn off it on this
page. Else, since EventValidation just ensure the postback is really raised
from the control self, you can use script to invoke a certain control's
postback event. e.g.
We can use script to trigger a button's click event at client-side:
document.getElementById("Button1").click();
How do you think? If you have any other consideration or ideas, please feel
free to post here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.