Reputation: 4523
I am trying to hide PlaceHolder2 and show PlaceHolder1 - on click of linkButton. Both are insider repeater.
Aspx
<form id="form1" runat="server">
<asp:Repeater ID="rptOnly" runat="server">
<ItemTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server" Visible="False">
//Display some images
</asp:PlaceHolder>
<asp:PlaceHolder ID="PlaceHolder2" runat="server">
<asp:linkbutton runat="server" id="lnkbtn" text="Click Here" OnClick="Myfunction_Click" />
</asp:PlaceHolder>
</ItemTemplate>
</asp:Repeater>
</form>
VB.net
Protected Sub Myfunction_Click(sender As Object, e As EventArgs)
PlaceHolder1.Visible = True
PlaceHolder2.Visible = False
End Sub
Upvotes: 0
Views: 1891
Reputation: 9193
Use FindControl from the RepeaterItem (as there could be multiple items in the Repeater) and then set the visibility.
EX for First Item in Repeater =
CType(rptOnly.Items(0).FindControl("PlaceHolder1"), PlaceHolder).Visible = True
CType(rptOnly.Items(0).FindControl("PlaceHolder2"), PlaceHolder).Visible = False
For all items in the repeater, do a For Each RPI as RepeaterItem in rptOnly.Items and do the same thing.
Edit from Comments:
Your particular issue would have you set the CommandName Property of your Button, which is also within the ItemTemplate, and change the visibility of the PlaceHolders in the ItemCommand Event of the Repeater.
CType(e.Item.FindControl("PlaceHolder1"), PlaceHolder).Visible = True
Upvotes: 1
Reputation: 7932
The repeater has a collection of items - You need to check each item in the collection:
For Each c As Control in rptOnly.Items
Dim p1 As Control = c.FindControl("PlaceHolder1")
Dim p2 As Control = c.FindControl("PlaceHolder2")
If p1 IsNot Nothing Then
p1.Visible = True
End If
If p2 IsNot Nothing Then
p2.Visible = False
End If
Next
Each item is a RepeaterItem: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeateritem_methods(v=vs.110).aspx
In Myfunction_Click
you should be able to find the placeholder as the control parent - something like this (you might need to cast the Parent object):
Protected Sub Myfunction_Click(sender As Object, e As EventArgs)
sender.Parent.Visible = True
sender.Parent.Visible = False
End Sub
Upvotes: 1