views:

333

answers:

2

Hi

So, I have a form to submit fighters. You write his/her name, country, and then the team they fight for + the team's country.

When you start typing the name I have constructed my own Ajax AutoCompleter. It will find existing fighters that might match.

When you click on one of the suggestions it will populate up to four fields depending on existing data in the database. If you're lucky the fighter already exists with information on country, team, and the team's country.

The problems starts when submitting. The JavaScript follows and just get's the id of the country to select (also the value of the select-option), and the select-element itself.

function dropdownSelect(value, element) {
    var dropdown = document.getElementById(element);
        for (var i = 0; i < dropdown.options.length; i++) {
            if (dropdown.options[i].value == value) {
                dropdown.options[i].selected = true;
                return true;
        }
    }
}

When submitting the ASP.NET-code halt's and says that my country-field is null. So my JavaScript-change of selected field couldn't be read by ASP.NET.

Is this a limitation of how ASP.NET works? Or a limitation of my skills? ;P

A: 

you can refer the following post http://stackoverflow.com/questions/623611/dynamically-created-dropdownlist-loses-listitems-on-postback

Elangovan
Thanx, but I have read that post and it's only about server-side issues. This isn't a change in .NET though but by JavaScript to one of the asp:DropDownList long after rendering. Seems like editing the DOM won't be read by ASP.NET when posting? Or can I with my JavaScript update the ViewState or something to solve this without rebuilding it all?
Bellfalasch
A: 

So, I've got the answer now.

ASP.NET fully supports JavaScript changing with the controls. That was what I wanted to find out for sure.

When I knew that I knew something else must have been wrong, so I dug around my code. I later found out that all my pages hade ViewState enabled, but my MasterPage had it Disabled, making for some weird behavior.

Now everything works fine after I activated ViewState on the MasterPage.

Bellfalasch