The client fills the DropDownList control with JavaScript the server side cannot read the value

Source: Internet
Author: User
Tags array copy client
There is no problem with padding, but the contents of the Drop-down table are not taken out on the server side. The page code is as follows.
Copy CodeThe 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"/><br/>
Your choice is: <asp:label runat= "Server" text= "Label" id= "Label1" ></asp:Label>
</div>
</form>

The background code to test is as follows.
Copy CodeThe code 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 that is populated by the client, nothing is read at all. DropDownList.Items.Count is 0,dropdownlist.selecteditem to null.
So, how do you get this value, you have to use the request.form["control's client ID". Shown in the following code.
Copy CodeThe code is as follows:
String S=request.form[typelist.clientid];

Attached: JavaScript file on page.
Copy CodeThe code is as follows:
<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>

End.

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.