如何在列表视图中找到控件的 ClientId?
这个问题非常类似于 如何查找ASP.NET GridView 中控件的客户端 ID?
但是,我使用的是列表视图和标签:
<ItemTemplate>
<asp:ImageButton ImageUrl="Resources/info.png" ToolTip="info" OnClientClick="toggle('<%#((label)Container).FindControl( "PresetUploadDescription").ClientID %>');" ID="Description" runat="server"/>
<asp:Label ID="UploadDescription" BorderStyle="Solid" BorderColor="Goldenrod" BorderWidth="1" runat="server" Width="40em" CssClass="sc-Upload-description" Text='<%# Eval("Description") %>'></asp:Label>
....
我在 findcontrol() 函数中收到“服务器标记格式不正确”...有什么想法吗?我尝试过“标签”和“控制”演员......
This question is very similar to
How do I find the Client ID of control within an ASP.NET GridView?
However I'm using a listview and a label:
<ItemTemplate>
<asp:ImageButton ImageUrl="Resources/info.png" ToolTip="info" OnClientClick="toggle('<%#((label)Container).FindControl( "PresetUploadDescription").ClientID %>');" ID="Description" runat="server"/>
<asp:Label ID="UploadDescription" BorderStyle="Solid" BorderColor="Goldenrod" BorderWidth="1" runat="server" Width="40em" CssClass="sc-Upload-description" Text='<%# Eval("Description") %>'></asp:Label>
....
I'm getting a "The server tag is not well formed" at the findcontrol() function...Any ideas why? I've tried both 'label' and 'control' casts...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,有两种方法可以完成您想要做的事情。使用
asp:ImageButton
服务器控件并使用OnItemDataBound
事件连接onclick
客户端事件,或者仅使用<输入 type="image" />
控件并内联连接ClientID
。以下示例显示了这两种方法:As far as I can tell, there are two ways to accomplish what you are looking to do. Either use an
asp:ImageButton
server control and wire up theonclick
client event using theOnItemDataBound
event, or simply use an<input type="image" />
control and wire up theClientID
inline. The following example shows both approaches: