views:

715

answers:

2

Hi,

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 !

+1  A: 

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.

BobbyShaftoe
Yeah I thought about that but I only get those exceptions while debugging...When I deploy my app to our test environment those exceptions never occur !!!!!
afgallo
Even though I had the EventValidation=true
afgallo
A: 

This may not be the problem...but are you checking for Page.IsPostBack in your Page_Load?

I've made that mistake way too many times.

If you are loading that drop down control from the Page_Load, and you are not checking if (!Page.IsPostback) you will reload the control. Then when you get the value from the drop down...the value is gone because you reloaded the dropdown.

Chris Brandsma
That's not the problem...I'm already checking that ...
afgallo