I have a listview control which is populated with data from a database. I have used the label to display that data. Now I need to use the value of that label in some other place. I am trying to access the text value of the label control but it says
Object reference not set to an instance of an object.
But I do have value in the label.
<asp:ListView ID="msg_list" runat="server">
   <ItemTemplate>
    <table>
      <tr class="myitem">
        <td>
            <asp:Label ID="reg_id_reply" runat="server" Text="helo" Visible="false"  />
             <asp:Label role="menuitem" ID="msg_lbl" runat="server" text='<%#Eval("msg")%>' /><i style=" color:Gray; " >  from   
             <asp:Label ID="tme" runat="server" Text='<%#Eval("name")%>' />
             <i> on </i>
             <asp:Label ID="tmelbl" runat="server" Text='<%#Eval("tme")%>'/>
              <a id="msg-reply" class="btn button" data-toggle="modal" data-target="#msg-rply" style="cursor:pointer;" ><i class="glyphicon glyphicon-share-alt white"> </i></a>  </td>
              <hr style=" margin-top:1px; margin-bottom:1px; " />
      </tr>
     </table>
     <%--<hr style=" margin-top:1px; margin-bottom:1px; " />--%>
   </ItemTemplate>
  </asp:ListView>
This is how i tried to access the text of the label.Note that the code below is inside a button click event onClick of buttom.
Label mylbl = (Label)msg_list.FindControl("reg_id_reply");
string rid = mylbl.Text;
 
     
    