我仍在使用 ASP 3.5。我有一个 ASP 用户控件:
*<%@ Control Language="C#" AutoEventWireup="true" CodeFile="GuideList.ascx.cs" Inherits="GuideList" %>
<asp:DropDownList ID="GL" ClientIDMode="AutoID" runat="server">
<asp:ListItem>Adam</asp:ListItem>
<asp:ListItem>Amanda</asp:ListItem>
<asp:ListItem>Bruce</asp:ListItem>
...
</asp:DropDownList>*
此控件多次放置在 ASPX 页面上:
*
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">
...
<p>First Guide <br />
<uc3:GuideList ID="GuideList1" runat="server" />
...
<p>Second Guide <br />
<uc3:GuideList ID="GuideList2" runat="server" />
...
<p>Third Guide <br />
<uc3:GuideList ID="GuideList3" runat="server" />
etc.
</asp:Content>
*
当我查看此页面的源代码时,我将控件的第一个实例视为:
<select name="ctl00$ctl00$ContentPlaceHolder1$main$GuideList1$GL" id="ctl00_ctl00_ContentPlaceHolder1_main_GuideList1_GL" ClientIDMode="AutoID">
如何在此页面的 Button1_Click 事件中按 ID 引用每个下拉框控件?以下都不起作用:
msg.Body = msg.Body + ctl00$ctl00$ContentPlaceHolder1$main$GuideList1$GL.Text.Trim() + "<br />"
msg.Body = msg.Body + ctl00_ctl00_ContentPlaceHolder1_main_GuideList1_GL.Text.Trim() + "<br />"
msg.Body = msg.Body + GL.Text.Trim() + "<br />"
msg.Body = msg.Body + <%= GL.ClientID %>.Text.Trim() + "<br />"
msg.Body = msg.Body + <%= ctl00_ctl00_ContentPlaceHolder1_main_GuideList1_GL.ClientID %>.Text.Trim() + "<br />"
msg.Body = msg.Body + <%= ctl00$ctl00$ContentPlaceHolder1$main$GuideList1$GL.ClientID %>.Text.Trim() + "<br />"
我只尝试过使用 AutoID,但我控制了所有代码,所以我不介意明确指定控件。
无论如何,谁能帮我解开这个神秘的谜语?从我看到的网络示例中,似乎 Javascript 与上面的 ID 一起工作得很好,而不是 VB。我究竟做错了什么?
谢谢,史蒂夫