Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7684107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:56:58+00:00 2026-05-31T18:56:58+00:00

What do I do get the dropdownlist to recognize it has a selected object?

  • 0

What do I do get the dropdownlist to recognize it has a selected object?
So I got the JQUERY AJAX JSON to populate a server control dropdownlist.
The user selects an option in the afore mentioned list.
Then clicks on a serverControl button.
I get a “Invalid postback or callback argument.” after trying for an hour or so to “use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation” I give up and set the EnableEventValidation=”false” in the page tag.
Now no more error but when I check the dropdownlist.selected value, it is empty.
What do I do get the dropdownlist to recognize it has a selected object?

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Ajax.aspx.cs" Inherits="something" EnableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>

    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" language="javascript">
           $().ready(function () {
                     $("#ddlCountry1").change(function () {
                         $.ajax({
                                type: "POST",
                                url: "Ajax.aspx/PopulateStates",
                                data: "{countryCode:" + "'" + bozo + "'" + "}",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (msg) {
                                       $("#ddlState").get(0).options.length = 0;
                                       $("#ddlState").get(0).options[0] = new Option("Select State", "-1");

                                       $.each(msg.d, function (value, item) {
                                              $("#ddlState").get(0).options[$("#ddlState").get(0).options.length] = new Option(item.Display, item.Value);
                                       });
                                       var itemCount = $("#ddlState").children().length;
                                       if (itemCount < 2) {
                                              $("#ddlState").hide();
                                       }
                                       else
                                       { $("#ddlState").show(); };
                                },
                                error: function () {
                                       alert("Failed to load states");
                                }
                         });
                  });
           });
    </script>

    </head>

and the form

    <body>
        <form id="form1" runat="server">
            <div>
               <table>
                   <tr><th>country</th><td>
                           <asp:DropDownList ID="ddlCountry1" runat="server" ClientIDMode="Static">
                           </asp:DropDownList>
                    </td></tr>
                <tr><th>state</th><td>
                        <asp:DropDownList ID="ddlState" runat="server" ClientIDMode="Static">
                           </asp:DropDownList>
                    </td></tr>
            </table>
        </div>
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </form>
</body>

and the code behind

 protected void Page_Load(object sender, EventArgs e)
      {
             BindCountryDropDown();
      }

      private void BindCountryDropDown()
      {
             ddlCountry1.Items.Add(new ListItem("country1", "country1"));
             ddlCountry1.Items.Add(new ListItem("country2", "country2"));
             ddlCountry1.DataSource = managers.profileManager.GetCountries();
             ddlCountry1.DataTextField = "CountryName";
             ddlCountry1.DataValueField = "CountryAbbr";
             ddlCountry1.DataBind();
      }

      [WebMethod]
      public static ArrayList PopulateStates(string countryCode)
      {
             var p = managers.profileManager.GetStates(countryCode);
             ArrayList myStates = new ArrayList(p.ToArray());
             return myStates;
      }


      protected void Button1_Click(object sender, EventArgs e)
      {
             var dd = ddlState.SelectedValue; //is empty
      }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:56:59+00:00Added an answer on May 31, 2026 at 6:56 pm

    The ASP.NET ID is not the client ID. It’s the internal ID for a postback. You can either look at the generated ID when it gets to the browser, or you can see the clientId attribute of the drop downs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to get the XML translation to HTML dropdownlist with ajax? I send the
I get that error in my GetForumsByForumGroupID method where it selects the Forum object
The premise: Get a dropdownlist's content based on the value selected in the first
I am struggling to get the selected value from the hard-coded dropdownlist in mvc
I have five DropDownList s linked together with the CascadingDropDown AJAX control. When it's
I've got this dropdownlist which I populate using programming code: while (teller < modellen.Length)
I'm looking for a solution to get the first selected item in a DropDownList.
I have a dropdownlist (on Page) which has OnSelectedIndexChange event thats Loads different Control
How to get dropdownList selected Item from CSHTML page. <div class=editor-field> @Html.DropDownList(ROUTE_GROUP_ID, String.Empty) @Html.ValidationMessageFor(model
I implemented this solution to get a MultiSelect DropDownList Box: http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/#filter However, it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.