I’m having trouble with a certain scenario. I have a repeater control, within I have a placeholder (and for the sake of testing, I’ve placed a div and tried that as well). I would like to, in my code behind page, find that placeholder or div, and put controls in it (for now, 3 textboxes and 2 buttons)
I have no issue with adding controls to a placeholder, I understand how that works, what I can’t get here, is how to find this dynamic control here.
Here is some code snippets to help illustrate what I’m trying to do.
(the asp)
<asp:Repeater id="rptSpecialNotes" runat="server">
<ItemTemplate>
<asp:UpdatePanel ID="udpSpecialNotesRepeater" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="plhSpecialNotesRepeater" runat="server">
</asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
<p><%# eval("subject") %></p>
<div id="specialNotes" runat="server"></div>
<asp:imagebutton runat="server" AlternateText="add Motion" ImageUrl="images/controls/Exclaim.png" width="40" height="40"></asp:imagebutton>
<asp:imagebutton runat="server" AlternateText="add document" ImageUrl="images/controls/Documents.png" width="40" height="40"></asp:imagebutton>
<asp:imagebutton runat="server" AlternateText="move up" ImageUrl="images/controls/Arrow-Up.png" width="40" height="40" CommandName="moveUp" CommandArgument='<%# Container.ItemIndex & "," & eval("ItemID") %>'></asp:imagebutton>
<asp:imagebutton runat="server" AlternateText="move down" ImageUrl="images/controls/Arrow-Down.png" width="40" height="40" CommandName="moveDown" CommandArgument='<%# Container.ItemIndex & "," & eval("ItemID") %>'></asp:imagebutton>
<asp:imagebutton runat="server" AlternateText="delete" ImageUrl="images/controls/Delete.png" width="40" height="40" CommandName="delete" CommandArgument='<%# Container.ItemIndex & "," & eval("ItemID") %>'></asp:imagebutton>
<asp:imagebutton runat="server" AlternateText="edit" ImageUrl="images/controls/Globe.png" width="40" height="40" CommandName="edit" CommandArgument='<%# Container.ItemIndex & "," & eval("ItemID") %>'></asp:imagebutton>
</ItemTemplate>
</asp:Repeater>
The image button edit, hits the rptSpecialNotes_Item command, which calls a method (edit special notes) which looks something like this
Dim commandArguments() As String = Split(e.CommandArgument, ",")
Dim divId As String = commandArguments(0)
Dim itemId As String = commandArguments(1)
'determine action based on command name
If e.CommandName = "edit" Then
Call editSpecialNotes(itemId,divId)
End If
and edit special notes is to place things in the given divID. For the sake of getting this to work, I’ve given divID a static value that I know exists (rptSpecialNotes_plhSpecialNotesRepeater_1) or something similar to that extent. However, I always end up with a null object reference.
Use
FindControlto get the nested control in therptSpecialNotes_Itemevent handler – this will return the control:It will return a
Controltype, so a cast is needed to the right type if you want to use the specific properties and methods of that type.