我无法获得名为" Select2"的第二个选择控件。 但我可以得到第一个选择控件" Select1"。 有人知道如何解决这个问题吗?
function ShowModalDialog(myData) {
gmyData = myData;
var x = document.getElementById("Select1");
var y = document.getElementById("Select2");
}
protected void btnPopup_Click(object sender, EventArgs e)
{
List<MyItem> myList = new List<MyItem>();
myList.Add(new MyItem("t1", "v1"));
myList.Add(new MyItem("t2", "v2"));
myList.Add(new MyItem("t3", "v3"));
string output = JsonConvert.SerializeObject(myList);
string szJS = "ShowModalDialog(" + output + ");";
ScriptManager.RegisterStartupScript(this, this.GetType(), "key1", szJS, true);
}
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<div id="dialog" style="display: none">
This is a simple popup
<br />
<select id="Select1" onchange="mySelectFunction1();" />
<select id="Select2" onchange="mySelectFunction2();" />
</div>
<asp:Button ID="btnPopup" runat="server" Text="Show Popup" OnClick="btnPopup_Click" />
</div>
</form>
</body>
</html>
答案 0 :(得分:0)
尝试在aspx页面的顶部设置ClientIDMode="Static"
。
这将客户端ID设置为与服务器控件的ID相同。
MSDN - Control.ClientIDMode Property