Reputation: 71208
without the repeater this works, but writing this inside repeater it's just compile error
<asp:Repeater runat="server" ID="rep1">
<ItemTemplate>
<li>
<o:TextBox runat="server" ID="txtLastName" />
<%
//this doesn't works outside of the repeater but here it doesn't
txtName.Text = txtLastName.ClientID;
%>
<o:TextBox runat="server" ID="txtName" />
</li>
</ItemTemplate>
</asp:Repeater>
Upvotes: 0
Views: 271
Reputation: 19220
You can only use DataBind syntax inside a ItemTemplate <%# %>
. If you want to refer to another control use the NamingContainer
.
<asp:Repeater runat="server" ID="rep1">
<ItemTemplate>
<li>
<o:TextBox runat="server" ID="txtLastName" />
<%# Container.FindControl("txtLastName").ClientID %>
<o:TextBox runat="server" ID="txtName" />
</li>
</ItemTemplate>
</asp:Repeater>
Otherwise you can always hook ItemDataBound
to manipulate the control on the server-side.
protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem)
{
var txtLastName = e.Item.FindControl("txtLastName") as TextBox;
var txtName = e.Item.FindControl("txtName") as TextBox;
...
}
}
Upvotes: 3