Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try the following as a demo. Server side DropDownLists are replaced with HTML select elements so that exception "Invalid postback or callback argument" doesn't happen. Drawback in this demo is that the values are not restored on form after postback. You can put this inside a form in Default.aspx:</p> <pre><code>&lt;script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function populate(populateInitial) { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: '/Default.aspx/populate', data: "{'populateInitial': '" + populateInitial + "'}", dataType: "json", async: false, success: function(result) { var ddlItems = document.getElementById('ddlItems'); ddlItems.options.length = 0; $.each(result.d, function(key, item) { ddlItems.options[key] = new Option(item); }); } }); } &lt;/script&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;select id="ddlItems" name="ddlItems"&gt; &lt;/select&gt; &lt;br /&gt; &lt;input type="button" onclick="populate('0');" value="Change values" /&gt; &lt;br /&gt; Selected item: &lt;asp:Label ID="lblSelectedItem" runat="server" Text=""&gt; &lt;/asp:Label&gt; &lt;br /&gt; &lt;asp:Button ID="Button1" runat="server" Text="Write out selected item text" /&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; populate('1'); &lt;/script&gt; </code></pre> <p>And you put these methods inside Default.aspx.cs:</p> <pre><code> protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { lblSelectedItem.Text = Request["ddlItems"].ToString(); } } [System.Web.Services.WebMethod()] [System.Web.Script.Services.ScriptMethod()] public static List&lt;string&gt; populate(string populateInitial) { if (populateInitial == "1") return (new string[] { "a", "b" }).ToList(); else return (new string[] { "c", "d", "e", "f" }).ToList(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload