why I cant access to literal in behind Code of my asp.net page?
<%@ Page Title="" Language="VB" MasterPageFile="~/UI/Masters/Window.master" AutoEventWireup="false" CodeFile="HelpViewer.aspx.vb" Inherits="UI_Pages_HelpViewer" culture="auto" meta:resourcekey="PageResource1" uiculture="auto" %>
<asp:Content ID="Content1" ContentPlaceHolderID="c" Runat="Server">
<%--<div dir="rtl">
<asp:Panel ID="Panel1" Height="270px" Width="100%" ScrollBars="Auto"
runat="server" meta:resourcekey="Panel1Resource1">
<asp:Literal ID="Literal1" runat="server" meta:resourceKey="Literal1Resource1"></asp:Literal>
</asp:Panel>
</div>--%>
<div dir="rtl" align="right">
<asp:Repeater ID="rptHelp" runat="server" DataSourceID="xmlHelp">
<ItemTemplate>
<div style ="font-size:12px; font-family :Tahoma; font-weight:bold; margin-left:5px; color:Green; ">
<asp:Literal ID="ltlTitle" runat="server" Text='<%#XPath("title")%>'></asp:Literal>
</div>
<div style="font-size:11px;margin-bottom:10px; margin-left:12px; margin-right:4px; font-family:Tahoma ; margin-top:9px;">
<asp:Literal ID="ltlText" runat="server" Text='<%#XPath("text")%>'></asp:Literal>
</div>
</ItemTemplate>
</asp:Repeater>
<asp:XmlDataSource ID="xmlHelp" runat="server"></asp:XmlDataSource>
</div>
</asp:Content>
ltlText is unknown element in behind code.
ltlText is unknown directly since it lives in a containing control: your repeater. If you want to get to it you need to iterate over the repeater rows, for example in the ItemDataBound event and there use the FindControl method to find your literal.
Take a look at the sample code in the MSDN documentation: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx.
The code you're after might look something like this:
rptHelp_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
Literal lt = (Literal)e.Item.FindControl("ltlText");
lt.Text = "Test";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With