DropDownList value not post back in ajax form

I encountered a bug with ajax form with DropDownList.
The selected value in DropDownList can't be posted to web server.
This bug only appears in IE (mine is 7.0.5730.11), but not in FF / chrome.

 Here is the sample code

// *************** CONTROLLER  ***************

        public ActionResult Test(int? page)
            return View();

// *************** CONTROLLER  ***************

<!-- *************** VIEW  *************** -->


<script src="<%= Url.Content("~/Scripts/MicrosoftAjax.js")%>" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.js")%>" type="text/javascript"></script>

    var pages = new int[] { 1, 2, 3, 4, 5 };
    int currentPage;
    if (!ViewData.ModelState.ContainsKey("page") ||
        !int.TryParse(ViewData.ModelState["page"].AttemptedValue, out currentPage))
        currentPage = 1;
<div id="container">
    <p>Page: <%= currentPage %></p>
    <% using (Html.BeginForm()) { %>
       <label>Normal "post back", which works</label>
       <%= Html.DropDownList("page", new SelectList(pages, currentPage))%>
       <%= Html.SubmitButton("nonajax", "Go") %>
    <% } %>

    <% using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "container", InsertionMode = InsertionMode.Replace })) { %>
       <label>Standard Ajax, always return to page 1</label>
       <%= Html.DropDownList("page", new SelectList(pages, currentPage))%>
       <%= Html.SubmitButton("ajax", "Go") %>
    <% } %>
    <% using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "container", InsertionMode = InsertionMode.Replace })) { %>
       <label>Hacked Ajax, but it works</label>
       <%= Html.DropDownList("page", new SelectList(pages.Select(p => new KeyValuePair<int, int>(p, p)), "Key", "Key", currentPage))%>
       <%= Html.SubmitButton("hackedajax", "Go") %>
    <% } %>

<!-- *************** VIEW  *************** -->

To make the sample looks simpler, ajax call return the whole html page, instead of a partial view. But it should be enough to show the problem.

11/6/2008 8:31:30 AM
asp.net.mvc 4300 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 54

Guess I should elaborate a bit.

There are 3 DropDownLists in the example.
1. Showing a normal, non-ajax "post back" as a control test case
2. Showing a standard ajax form
3. Showing an ajax form with a hacked DropDownList

This serves 2 purposes
1. Is it my own problem? Or many of us can repeat this problem?
2. Is there an official fix/workaround for this?

11/6/2008 10:26:46 AM

Similar Artilces:

FORM values on post back
 okay... another dumb nubie question here... I am building a form with three dropdown controls to drill down through category, sub-category and product. I have each set to post back so that when the user selects the main category the sub-category  should be populated  based on the value of  the main control. The controls (or at least the first one) are binding to a WebService class. But or some crazy reason I can't seem to access the value of the main category to supply it to the sub category WebService. However the selected value of the main category is mai...

Form DropDownList not posting back
I made this form with a DropDown box. It refreshes the page when you select an item, but it doesn't post back the information. I can't figure out why. The Request.Form("cboFilter") never gives me anything but an empty string. Why is this?Okay here's my code in the form runat=server part:<asp:DropDownList ID = "cboFilter" runat = "server" AutoPostBack = "true"></asp:DropDownList> Then here's my code-behind: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load    Dim fi...

Dropdownlist not posting back selected values.
My data base looks like this. My dropdownlist has the vacancy_num as the DataTextField and  description as DataValueField. If I select a vacancy_num and do a post back to place the 'description' name as a label using the DataValueField for the value, The vacancy_num ALWAYS selects the first vacancy_num in the sequence. Example: I choose B1000/2. Postback returns B1000/1. I choose B4000/3, postback returns B4000/1. Why does it not keep the value I selected?? I have noticed that if I replace the DataValueField to point to the vacancy_num it works fine. But then I don't have a descri...

Value of DropDownList without post back
I have a DropDownList populated by an ArrayList (manually filled). I want to capture the SelectedIndex value of the DropDownList at form submission. All attmepts have left me with the first value of the list, and not the selected item. Is it not possible to get this value to change without the _OnSelectedIndexChange event on postback? M A common cause of this is re-binding the dropdown in PageLoad on every postback. That causes the user's selection to be overlayed before the page processing cycle reaches the point where your postback events are processed. Check "If Not Is...

Prevent browser refreshes from posting back an already-posted-back form?
HiI have a formview in insert mode for inserting items into a gridview.  Each item is some description text, a price, and a quantity.  I'm using SqlDataSource controls while I learn about the New Way of Doing Things.If I insert an item, and then refresh the now-posted-back page in my browser, the same item gets inserted again.  I would like to prevent this, ideally without response.redirecting on FormView.ItemInserted every time a new item is inserted.  I don't think it'd be a question of clearing the inputs and validating for data, would it?  I mean, an F5 will repo...

Does AJAX Post all form data back to server?
Hi allRecently, I am studying Asp.net AJAX and find one question. Please see below code excerpt:<form id="form1" runat="server">  Maxium: <asp:TextBox  runat=server ID=maxValue Text=2500 /> <br />   <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />            Result: <asp:UpdatePanel runat =server ID="ResultPanel">                 &nb...

DropDownList and CheckBoxList not holding value during post back
Hi, I have a dropdownlist (and a CBL) that is not holding it's selectedIndex value when the page is posted back.  I've looked for answers and have seen and tried many things such as setting autoPostBack/enableViewState/etc.  But, nothing is working....  Any ideas?  I've also read that certain controls do not by default post their values back if they are within an HTML table that is within a HTML form.  As I know, all of my asp.net server controls are within the aspnetform form on the rendered page and both of these server controls are within a table. ...

where is the value saved of the form controls(such as textbox) in post backs?
hello! I have some puzzle in view state.I have just read an article in Msdn about view state.http://msdn2.microsoft.com/en-us/library/ms972976.aspx,It says, there are many stages in the life cycle of the page,and the Stage 2 is Load View State,the Stage 3  is Load Postback Data.In Stage 2 ,it says : During this stage, the view state data that had been saved from the previous page visit is loaded and recursively populated into the control hierarchy of the Page. And the Stage 3 is Load Postback data of the form controls, My first question is: what is the difference of the view stat...

Trouble getting selected value from DropDownList when posted back
I have a DropDownList inside a Repeater with AutoPostBack=True. I need to get the selectedvalue of the DropDownList so that I can populate another DropDownList based on its value. I was trying to do this in the Page_Load method but the value is coming back as null. Here's what I was trying. What am I doing wrong? Thanks <asp:DropDownList ID="OfficeDDL" runat="server" AutoPostBack="true" /><br />  if (Page.IsPostBack) { DropDownList OfficeDDL = (DropDownList)EmployeeOfficeAddressRepeater.FindControl...

AJAX modalpopup to post data back to web form
I have a form with a button on it.  When the button is clicked, an ajax modalpopup is displayed  and the user can then input some data into a text field and click another button that will query a database and return with a gridview of information pulled from the database.  In the code behind I have the gridview_selectedIndexChanging set up to catch the index of the selected row and then pull the data from the cells into hidden text fields all within the popup.  The OK button is tied to some code behind that should transfer the values in the hidden text fields to...

After post back insert row in datagrid from form values
I am looking for the best control to allow the insert of row or rows based on form values from post back.  This must be old but after two hours of search, I cannot find simple example of inserting row into datagrid without calling ds from db.  DataGrid can not be editable and is few columns of simple strings.  On postback I want to add new row to data grid while preserving row that is there.  Using a session datatable is not an option as I do not want the table to expire with time.  Thanks for any assistance in finding an example of this (what must be typic...

Posting Values Form to Form Same App
Hello, all I am attempting to understand how to pass form field values to another page's form field values. I can set up the Get values, Server.Transfer and discover the values that have been passed, but my problem is setting these values to the receiving page server side controls (textboxes in this case). Any help in understanding this is appreciated. Here's a simplified source: First Page:     Has Two Fields on a form     After validating, redirect to second page   Second Page:     Has Two fields on a form     Reads...

How to maintain form controls value after user control post back?
 hello experts, I have created filter grid in asp.net & C#.My form design has contains 3 dropdown controls and Filter grid(User control).Its working fine(filter), but one problem arise.the form controls are clear when i filter a grid(post back).I tried to reterive values using view state, hidden controls, i got only null values.Anyone please help, its urgent to me. Its my user control code.FilterGrid.aspx<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FilterGrid.ascx.cs" Inherits="FilterGrid" %><style type = "text/css&...

How to Pass data to pop up form, allow user to add new value, pass new value back to form to do Insert
I have a grid view that shows the user the last meter readings (hours) for several generators. The meter readings need to be added daily.  I would like the user to be able to select the meter record from the grid view and have a pop up javascript form open that would allow the user to enter a new meter reading. Then after I do validation, do an insert of the new reading to the database. Is that a reasonable way of doing what I want? If not, can you give me a suggestion as to how to do it differently. Thanks. Hi..   Instead of opening window to ente...

Web resources about - DropDownList value not post back in ajax form - asp.net.mvc

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 12/20/2015 2:19:52 AM