After extensive research from reading about Script Manager and trial and error, here is what I found.
You can disable event validation, but that is not always the best option because it's good practice to have both JavaScript validation as well as ASP.NET validation. That is the whole purpose of registering these values in your dropdowns. If you have JavaScript that injects options into your select (a select renders from an ASP.NET DropDownList control) you want to prevent script injection whenever possible.
ANSWER TO MY QUESTION: So to do this, we call this RegisterForEventValidation for EVERY possible value that can ever appear in that dropdown for any possible situation in your application. In my case, I had two dropdowns. One dropdown used to cause a postback and re-populated the second dropdown with values based on the first dropdown. However, now I'm using JavaScript to inject the values into the dropdown with jQuery.
Before re-populating the values, I remove all values with jQuery.
jQuery("#<%=DDLTest.ClientID %>").children("option").each(function() {
jQuery(this).remove();
});
When my first dropdown changes, I repopulate the second dropdown with the values relevant for the first dropdown value.
var map = {
"1112": "Hair 5 Drug Panel",
"1121": "Hair 5 Drug Panel and Extended Opiates Limit of Detection Test",
"1120": "Hair 5 Drug Panel Limit of Detection Test"
};
var thisTemp = this; // the reason I do this is because "this" is already being used in the callback.
jQuery.each(map, function(key, val) {
jQuery(thisTemp.Elements.DDLTest).append(jQuery("<option></option>").val(key).text(val));
});
And select the value I need.
jQuery(this.Elements.DDLTest).val(quickDataEntryObject.TestPricingOptionId);
However, before all this JavaScript stuff happens, I am registering the possible values for the dropdown. You MUST do this in the Render event.
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim testPricingOptionTable As DataTable = ApplicationContext.Database.ExecuteDataSet("procEventValidationRegisteredValues", "test_pricing_options").Tables(0)
For Each testPricingOptionRow As DataRow In testPricingOptionTable.Rows
Page.ClientScript.RegisterForEventValidation(DDLTest.UniqueID, testPricingOptionRow(0).ToString)
Next
MyBase.Render(writer)
End Sub
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…