드롭 다운 목록에 선택한 객체가 있음을 인식하게하려면 어떻게해야합니까? JQuery AJAX JSON을 사용하여 서버 컨트롤 드롭 다운 목록을 채 웁니다. 사용자는 앞서 언급 한 목록에서 옵션을 선택합니다. 그런 다음 serverControl 버튼을 클릭하십시오. "잘못된 포스트 백 또는 콜백 인수가 있습니다." 1 시간 정도 후에 "유효성 검사를 위해 포스트 백 또는 콜백 데이터를 등록하기 위해 ClientScriptManager.RegisterForEventValidation 메서드를 사용합니다"라고 말한 다음 페이지 태그에 EnableEventValidation = "false"를 설정합니다. 더 이상 오류가 없지만 dropdownlist.selected 값을 확인하면 비어 있습니다. 드롭 다운 목록에 선택한 객체가 있음을 인식하도록하려면 어떻게해야합니까?Jquery Ajax ServerControl DropDownlist ajax 호출 후 선택한 항목
<%@ 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>
양식
<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>
및
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
}
그래서 자바 스크립트를 통해해야합니까? – user1069733