使用动态ID在ASP中创建控件 [英] Creating controls in ASP with dynamic IDs

查看:79
本文介绍了使用动态ID在ASP中创建控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个聊天小部件,它将被放入CommunityServer中。该小部件效果很好,但是我发现如果将其中两个小部件放到同一页面上,则只有其中一个有效!而且我非常确定,原因是因为聊天窗口是在ASP中定义的,所以现在在同一页面上有两个具有相同ID的聊天窗口实例。

I'm creating a chat widget that will be dropped into CommunityServer. The widget works great, but I just discovered that if I drop two of these widgets onto the same page, only one of them works! And I'm quite certain the reason is because the chat window is defined in ASP, and now there are two instances of the chat window, with the same ID, on the same page.

我正在使用纯ASP& Javascript(不是强制选择的),所以我的聊天窗口定义为:< telerik:RadListBox ID = rlbMessages runat = server> (不要介意

I am doing this with straight ASP & Javascript (not by choice), so my chat window is defined as: <telerik:RadListBox ID="rlbMessages" runat="server" > (don't mind that it's a telerik control).

所以我希望我可以做这样的事情:< telerik:RadListBox ID =<% ='rlbMessages'+ chatRoomID%> runat = server>

So I was hoping I could do something like this: <telerik:RadListBox ID="<%= 'rlbMessages' + chatRoomID %>" runat="server" >

但是从我收集到的信息来看,显然您不能以这种方式分配ID吗?替代方法是什么?

But from what I've gathered, apparently you can't assign ID's this way? What is the alternative?

推荐答案

通常,使用Telerik和.NET时,您会发现代码喜欢拥有所有ID。解决方法是,可以使用唯一的CSS类名称。

With Telerik and .NET in general you'l find the code likes to own all the IDs. As a work-around you can use unique CSS class names.

这篇关于使用动态ID在ASP中创建控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆