ASP.NET - Ajax requests with jQuery
I have this textBox that triggers 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 box 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 perfectly. The only problem I am having is that when I update my formView code to save this entry, I cannot see the values ββthat were set for this dropdown. Since I am populating this client side dropdown menu, my guess is that ASP.NET does not handle this.
Does anyone have any ideas?
Apparently when I enable / disable the EnableEventValidation property for this page, I sometimes get the correct value .....
Thank!
source to share
It might not be a problem ... but are you checking the .IsPostBack in your Page_Load?
I've made this mistake too many times.
If you load this dropdown control from Page_Load and you don't check if (! Page.IsPostback) you will reload the control. Then when you get the value from the dropdown ... the value is gone because you reloaded the dropdown.
source to share