Last post Oct 01, 2009 07:24 AM by Hua-Jun Li - MSFT
Sep 27, 2009 02:18 AM|qwsoftdraw|LINK
I have controls with ID's and the Runat="server" for each control inside of a <ItemTemplate> for a Repeater Control, but the Controls cannot be found when I'm using VBScript. I have no problem finding Controls in VBScript when the Controls are NOT inside
of a Repeater section like the <ItemTemplate>. Is there any reason the controls do not show up, and is there a work around?
Thanks in advance for any useful help.
Sep 27, 2009 07:00 AM|tdinpsp|LINK
I have had similar problems though with other controls such as FormView. I think the problem stems from whether the <ItemTemplate> is currently active. You have to be very careful as to when you try to access a control within a template. If you are absolutely
sure that the ItemTemplate is active at the time when you try to access a control I have also found that sometime if you walk the child controls of the parent control you can sometimes find it that way rather than using FindControl.
Sep 27, 2009 10:24 AM|mendhak|LINK
It depends on how you're trying to find it and how you're generating that code to find it. When you place a control in a repeater, its ID changes because there are now multiple instances of it, so it adds prefixes to the ID. In order to find the control
with client side scripting, you'll need to generate the script from the codebehind by using the control's ClientID property.
Sep 29, 2009 02:44 AM|qwsoftdraw|LINK
That makes sense that it making multiple copies with multiple IDs.
I'm using Visual Web Developer 2008 Express Edition. Normally, when I am building code in the <script></script> area in VBScript and I type in the name of the control, it will find the name and and the properties with it. It just doesn't find the control
for anything inside of the <ItemTemplate> doing it this way. Occasionally, I stumble across something like this that there is just no good solution for it. Ultimately what I am trying to do is set up 2 <td>'s inside a Table inside the <ItemTemplate> with 2
scenarios. With scenerio #1, the first <td> would be visible="true" and the second <td> would be visible="false". Scenerio #2 would be the opposite with the first <td> being visible="false" and the second <td> visible="true". All this needs to happen before
the final output for the client to view i.e. it all happens in Page_Load ().
Sep 29, 2009 04:04 PM|mendhak|LINK
Do you mean VBScript or VB.NET? VBScript was used in classic ASP and is also used as a client-side scripting language for IE-only. VB.NET is a "codebehind" language that you can use with ASP.NET pages. Can you clarify please!
Oct 01, 2009 07:24 AM|Hua-Jun Li - MSFT|LINK
Because you put these controls inside the reapter control, it equal to put it into container control.
The 'Findcontrol' method is only to retrieve the current container, it do't search it looply, you can't find it.
You can use the following way:
Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If ((e.Item.ItemType = ListItemType.Item) _
OrElse (e.Item.ItemType = ListItemType.AlternatingItem)) Then
Dim lblName As Label = New Label
lblName = CType(e.Item.FindControl("lblName"),Label)
Dim strName As String = lblName.Text.ToString
Please check the following link:
If you want to get control at client webpage, plase use the following way: