I’ve got this textBox which triggers off an ajax request using jQuery:
<asp:TextBox ID='postcodeTextBox' runat='server' Text='<%# Bind('POSTAL_ZIP_CODE') %>'> $(document).ready(PageLoad); function PageLoad() { $(container + 'parentProjectTextBox').change(GetProjectName); } function GetProjectName() { var projectNumber = $(this).val(); if (projectNumber == '') return; $(container + 'parentProjectPanel').block({ message: '<img src='../Resources/RadControls/Ajax/Skins/Default/loading7.gif' />' }); $.ajax({ type: 'POST', url: projectMasterWebServicesUrl + 'GetProjectName', data: '{'projectNumber':'' + projectNumber + ''}', contentType: 'application/json; charset=utf-8', dataType: 'json', success: GetProjectNameOnSuccess, error: GetProjectNameOnError }); }
This ajax request gets a list to populate this dropdown:
<asp:DropDownList ID='cityDropDownList' runat='server' OnDataBound='cityDropDownList_DataBound'> <asp:ListItem Text='...Select...' Value='0'> </asp:ListItem> </asp:DropDownList>
Everything works fine. The only problem I’m having is that when I update my formView priod to saving that record I can’t see the value that was set to that dropdown. As I’m populating this dropdown in the client side I supose ASP.NET loses track of that ….
Does anyone have any insights?
Apparently when I switch on/off the EnableEventValidation property for that page I sometimes get the correct value…..
Thanks !
You should create a hidden field store that value. Update that HiddenField in your Javascript and then read it on the server side. Also, if you have EventValidation=true and you change the items in the dropdown list you will get well known exceptions.