开发者

Is that possible to use a same user control in a page for multiple times?

It's all about the control id. I am developing chat function in my asp.net project. I need to show a chat div for a target user that the current user is chatting with. Each chat div is loaded a user control. I'm wondering if there are more than one control shows in a same web page, what is the control id. For example, there is a textbox in user control id="tb1". If there are two user controls in a page, do the two textbox share a same id? I'm asking because I found that, even two chat div shows up, the content in the div are same whic开发者_如何学编程h I don't know why.


Yes, you can use the same control as many times as you want in the same page.

Since each user control will have a different ID, the child controls within it will have a different id based off of the container control's id as long as all of them are server controls (i.e. have the runat="server" tag).


No, the TextBoxes will not have the same ID. Because they are in different user controls, they will be assigned two different ClientIDs.

You can see the IDs of the controls by viewing the source of the page in the browser. The ClientID will look something like this: ctl00_ContentBody_tb1_TextBox1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜