Client is populated with JavaScript DropDownList control server-side read value

Source: Internet
Author: User

Padding does not have any problems, but the content in the drop-down table is not taken out on the server side. The page code is as follows.

<form id= "Form1" runat= "Server" >
<div>
Three cascading drop-down list boxes:
<asp:dropdownlist runat= "Server" id= "bigtypelist" width= ">"
</asp:DropDownList>
<asp:dropdownlist runat= "Server" id= "typelist" width= ">"
</asp:DropDownList>
<asp:dropdownlist runat= "Server" id= "smalltypelist" width= ">"
</asp:DropDownList>
<br/>
<asp:button runat= "Server" text= "read drop-down table" id= "OK" onclick= "OK_Click"/><br/>
You chose: <asp:label runat= "Server" text= "Label" id= "Label1" ></asp:Label>
</div>
</form>

The background code used for testing is as follows.

protected void OK_Click (object sender, EventArgs e)
{
listitem[] array = new LISTITEM[3];
Array[0] = Bigtypelist.selecteditem; Is null
ARRAY[1] = Typelist.selecteditem; Is null
ARRAY[2] = Smalltypelist.selecteditem; Is null
}

It turns out that when the server-side reads the value of the DropDownList control populated by the client, nothing is read at all. DropDownList.Items.Count is null for 0,dropdownlist.selecteditem.
So, how to get this value, we have to use request.form["control's client ID"]. As shown in the following code.

String S=request.form[typelist.clientid];

Attached: JavaScript files in the page.

<script language= "javascript" type= "Text/javascript" >
$ (function () {
var bigid = ' #<%=bigtypelist.clientid%> ';
var mediumid = ' #<%=typelist.clientid%> ';
var smallid = ' #<%=smalltypelist.clientid%> ';
$ (bigid). CascadingDropDown (Mediumid,
‘.. /services/autotypeservice.asmx/getautotype ',
{valuemember: ' id ', DisplayMember: ' Name ', Cascadingargname: ' Parent '});
$ (mediumid). CascadingDropDown (Smallid,
‘.. /services/autotypeservice.asmx/getsubautotype ',
{valuemember: ' id ', DisplayMember: ' Name ', Cascadingargname: ' Parent '});
});
</script>

Client is populated with JavaScript DropDownList control server-side read value

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.