title: access img tag inside asp:FormView at codebehind
body: <p>I have a asp .net form and need to check a specific image tags current image and move ahead , refer the markup below </p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="SessionDetails.aspx.cs" Inherits="CodeCamper.UIWebLayer.WebUI.SessionDetails" %&gt;
  &lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %&gt;
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"&gt;
       &lt;script&gt;         
           var changeState = false;
           var counter = 0;
           function changeImage(elementaccess) {
               if (elementaccess == false &amp;&amp; changeState == false &amp;&amp; document.getElementById("bookmarkimage").getAttribute("src") === "/Images/blue-bookmark.png") {
                   document.getElementById("bookmarkimage").setAttribute("src", "/Images/heart-black.png");
                   document.getElementById("bookmarkimage").setAttribute("title", "Add To Favorite"); 
               }
               else if (elementaccess == false &amp;&amp; changeState == false &amp;&amp; document.getElementById("bookmarkimage").getAttribute("src") === "/Images/heart-black.png") {
                   document.getElementById("bookmarkimage").setAttribute("src", "/Images/blue-bookmark.png");
                   document.getElementById("bookmarkimage").setAttribute("title", "Add To Favorite");
               }
               else if (counter == 0 &amp;&amp; elementaccess == true &amp;&amp; (document.getElementById("bookmarkimage").getAttribute("src") === "/Images/heart-black.png" || document.getElementById("bookmarkimage").getAttribute("src") === "/Images/blue-bookmark.png")) {
                   counter = 1;
                   document.getElementById("bookmarkimage").setAttribute("src", "/Images/heart-checked.png");
                   document.getElementById("bookmarkimage").setAttribute("title", "Remove Favorite");
               }
               else if (counter == 1 &amp;&amp; elementaccess == true &amp;&amp; document.getElementById("bookmarkimage").getAttribute("src") === "/Images/heart-checked.png") {
                   counter = 0;
                   document.getElementById("bookmarkimage").setAttribute("src", "/Images/blue-bookmark.png");
                   document.getElementById("bookmarkimage").setAttribute("title", "Add To Favorite");
               }
           }
      &lt;/script&gt;
  
      &lt;div class="generalmargin" style="margin-top: 160px"&gt;
          &lt;%--&lt;asp:Button ID="Buttonback" runat="server" Text="" class="button-back"/&gt;--%&gt;
  
      &lt;/div&gt;
      &lt;div id="labelinfo" style="text-align: center;" runat="server"&gt;
          &lt;span id="spanlabelinfo" class="text-danger" style="align-content: center" runat="server"&gt;Error
          &lt;/span&gt;
      &lt;/div&gt;
      &lt;div style="margin-top: 160px"&gt;
          &lt;asp:LinkButton ID="ButtonBack" runat="server" class="btn btn-default btn-md glyphicon glyphicon-backward" Text="" OnClientClick="JavaScript:window.history.back(1);return false;"&gt;
          &lt;/asp:LinkButton&gt;
           &lt;asp:LinkButton ID="ButtonCancel" runat="server" class="btn btn-default btn-md glyphicon glyphicon glyphicon-remove-sign" Text="" OnClick="ButtonCancel_Click"&gt;
          &lt;/asp:LinkButton&gt;
          &lt;asp:LinkButton ID="ButtonSave" runat="server" class="btn btn-default btn-md glyphicon glyphicon-floppy-disk" Text="" OnClick="ButtonSave_Click"&gt;
          &lt;/asp:LinkButton&gt;        
      &lt;/div&gt;
       &lt;asp:FormView ID="sessionDetail" runat="server" ItemType="CodeCamper.EntityLayer.Transaction.SessionVO" SelectMethod="GetDetails"  RenderOuterTable="false"&gt;
          &lt;ItemTemplate&gt;
              &lt;div&gt;
                  &lt;h3&gt;&lt;%#: Item.SessionTitle %&gt;&lt;/h3&gt;
              &lt;/div&gt;
              &lt;br /&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td style="width:25%"&gt;                      
                          &lt;label&gt;Track&lt;/label&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;%#: Item.SessionTrack %&gt;&lt;br /&gt;&lt;label&gt;Time Slot&lt;/label&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;%#:Item.SessionTimeSlot %&gt;&lt;br /&gt;&lt;label&gt;Room&lt;/label&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;%#:Item.SessionRoom %&gt;&lt;br /&gt;&lt;label&gt;Level&lt;/label&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;%#:Item.SessionLevel %&gt;&lt;br /&gt;&lt;label&gt;Tags&lt;/label&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;%#:Item.SessionTags %&gt;&lt;br /&gt;&lt;image src='/Images/photos/&lt;%#:Item.ImagePath%&gt;' /&gt;                        
                      &lt;/td&gt;
                      &lt;td style="width:75%"&gt;&lt;label&gt;Description&lt;/label&gt;&lt;br /&gt;
                          &lt;div class="pre-scrollable"&gt;&lt;%#:Item.SessionBio %&gt;&lt;/div&gt;                       
                      &lt;/td&gt;                  
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td style="width:25%"&gt;                      
                           &amp;nbsp;              
                      &lt;/td&gt;
                      &lt;td style="width:75%"&gt;
                      &lt;img src='/Images/blue-bookmark.png' ID="bookmarkimage"  onmouseover="changeImage(false);" onmouseout="changeImage(false);" onclick="changeImage(true);" /&gt;&lt;br /&gt;
                          &lt;br /&gt;
                         &lt;%-- &lt;cc1:Rating ID="SeesionRating"  runat="server"
                              StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
                              FilledStarCssClass="FilledStar" ReadOnly="True" CurrentRating=&lt;%#: int.Parse(Item.SessionRating.ToString()) %&gt;&gt; 
                          &lt;/cc1:Rating&gt;--%&gt;
                           &lt;cc1:Rating ID="SeesionRating"  runat="server"
                              StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
                              FilledStarCssClass="FilledStar" ReadOnly="True" CurrentRating=&lt;%# Item.SessionRating %&gt;&gt; 
                          &lt;/cc1:Rating&gt;
                      &lt;/td&gt;                  
                  &lt;/tr&gt;
              &lt;/table&gt;
                  &lt;asp:HiddenField runat="server" ID="isAddedFav" Value="0"&gt;&lt;/asp:HiddenField&gt;
          &lt;/ItemTemplate&gt;
      &lt;/asp:FormView&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>in code behind </p>
  
  <pre><code>protected void ButtonSave_Click(object sender, EventArgs e)
          {
               labelinfo.Visible = true;
               //HiddenField h1 = sessionDetail.FindControl("isAddedFav") as HiddenField;
               //labelinfo.InnerHtml = h1.Value;
               Image h2 = sessionDetail.FindControl("bookmarkimage") as Image;
               labelinfo.InnerHtml = h2.ImageUrl;
               labelinfo.Attributes["class"] = "centering text-center text-info";
          }
  </code></pre>
  
  <p>the question is Image h2 = sessionDetail.FindControl("bookmarkimage") as Image; returns null</p>
  
  <p><strong>I want to check the image is heart-checked.png or not</strong> </p>