Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET Accessing web control inside DataList control
    text
    copied!<p>Am not sure why I cannot access my Label control which was inside the Panel and the Panel is inside the DataList</p> <pre> &lt;asp:DataList ID="DataList2" runat="server" DataSourceID="SqlDataSource1" Width="100%"> &lt;ItemTemplate> &lt;table border="0" cellpadding="0" cellspacing="0" width="100%"> &lt;tr> &lt;!-- post details --> &lt;td style="width: 60%"> &lt;asp:Panel ID="panelPostDetails" runat="server" CssClass="postpage_details"> &lt;table border="0" cellpadding="5" cellspacing="0" width="100%"> &lt;tr> &lt;td colspan="2">&lt;div class="postpage_header">&lt;%# Eval("Heading") %>&lt;/div>&lt;/td> &lt;/tr> &lt;tr> &lt;td> &lt;img src="picserver/posts/&lt;%# Eval("ImagePath") %>/1.jpg" alt="preview" style="width: 240px;" /> &lt;div id="morepictures"> &lt;asp:Label ID="lblMorePictures" runat="server" /> &lt;/div> &lt;/td> &lt;td> &lt;div style="padding: 0px 5px 0px 5px;"> &lt;div> more stuff here &lt;/div> &lt;/div> &lt;/td> &lt;/tr> &lt;/table> &lt;/asp:Panel> &lt;asp:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server" Radius="6" Corners="All" TargetControlID="panelPostDetails">&lt;/asp:RoundedCornersExtender> &lt;/td> &lt;/tr> &lt;/table> &lt;/ItemTemplate> &lt;/asp:DataList> </pre> <p>but when I tried using "lbl" in Page_Load, it seems it cannot find the control? can you please help me?</p> <pre> ItemDataBound and Page_Load event --------------------------------- Panel p = DataList2.FindControl("panelPostDetails") as Panel; Label l = p.FindControl("lblMorePictures") as Label; l.Text = code; </pre> <p>that code returns <b>Object reference not set to an instance of an object.</b></p> <p>Thanks in advance</p> <p>update:</p> <pre> ItemDataBound and Page_Load event --------------------------------- Panel p = DataList2.FindControl("panelPostDetails") as Panel; if(p==null) { System.Diagnostic.Debug.WriteLine("panel does not exist"); } else { System.Diagnostic.Debug.WriteLine("panel does exist"); } output: panel does not exist </pre> <p>what on earth is going on!?!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload