Note that there are some explanatory texts on larger screens.

plurals
  1. POObject reference not set to an instance of an object
    primarykey
    data
    text
    <p>I am trying to assign values to the hiddenfields duting page_load..but its throwing System.NullReferenceException.. This is the code iam using in the page_load event..</p> <pre><code> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim hLogInfo As HiddenField = DirectCast(FindControl("HLogInfo"), HiddenField) Dim hUName As HiddenField = DirectCast(FindControl("HUName"), HiddenField) If Not Page.User.Identity.IsAuthenticated Then Response.Write("not logged in") hLogInfo.Value = "No" hUName.Value = "None" Else Dim currentUser As MembershipUser = Membership.GetUser() hUName.Value = currentUser.UserName Response.Write(currentUser.UserName) hLogInfo.Value = "Yes" End If End Sub </code></pre> <p>Given below is the error details...</p> <pre><code> Server Error in '/colorshelf.com' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 41: Else Line 42: Dim currentUser As MembershipUser = Membership.GetUser() Line 43: hUName.Value = currentUser.UserName Line 44: Response.Write(currentUser.UserName) Line 45: hLogInfo.Value = "Yes" Source File: G:\Websites\colorshelf.com\html\*******.***.vb Line: 43 Stack Trace: [NullReferenceException:Object reference not set to an instance of an object.] ****_****.Page_Load(Object sender, EventArgs e) in G:\Websites\colorshelf.com\html\******.***.vb:43 System.Web.UI.Control.OnLoad(EventArgs e) +91 System.Web.UI.Control.LoadRecursive() +74 System.Web.UI.Control.LoadRecursive() +146 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 </code></pre> <p>Modifying the code like the one bewlow too throws the same error</p> <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.User.Identity.IsAuthenticated Then Response.Write("not logged in") HLogInfo.Value = "No" HUName.Value = "None" Else Dim currentUser As MembershipUser = Membership.GetUser() HUName.Value = currentUser.UserName Response.Write(currentUser.UserName) HLogInfo.Value = "Yes" End If End Sub </code></pre> <p>Given below is the page source..</p> <pre><code>&lt;%@ Master Language="VB" MasterPageFile="../**.master" AutoEventWireup="false" CodeFile="***.master.vb" Inherits="***_****" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server"&gt; &lt;asp:ContentPlaceHolder ID="HeadContentSubMaster" runat="server"&gt; &lt;script type="text/javascript"&gt; &lt;/script&gt; &lt;/asp:ContentPlaceHolder&gt; &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server"&gt; &lt;div style="width: 100%; float: left;"&gt; &lt;div style="width: 16%; float: left;" align="center"&gt; &lt;div style="color: #FFFFFF; font-weight: bold; font-size: 14px; width: 100%; padding-top: 37px;" align="center"&gt; Colorshelf list &lt;br /&gt; &lt;hr width="70%" /&gt; &lt;/div&gt; &lt;table border="0" style="border-collapse: separate; padding-top: 7px;"&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;div style="width: 56%; float: left; margin-left: 20px;"&gt; &lt;asp:ContentPlaceHolder ID="BodyContent" runat="server"&gt; &lt;/asp:ContentPlaceHolder&gt; &lt;/div&gt; &lt;div style="width: 22%; float: right;"&gt; &lt;a href="http://www.lalsofttech.com/MRanking/Default.aspx" style="border-style: none"&gt; &lt;img src="../Images/MRA_Banner.png" style="border-style: none; width: 92%; padding-left: 30px; padding-top: 50px;" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div style="width: 100%; float: left;"&gt; &lt;div style="width: 80%; float: left;"&gt; &lt;asp:ContentPlaceHolder ID="ContentFooter" runat="server"&gt; &lt;asp:HiddenField ID="HLogInfo" runat="server" Value="" /&gt; &lt;asp:HiddenField ID="HUName" runat="server" Value="" /&gt; &lt;/asp:ContentPlaceHolder&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="clear"&gt; &lt;br /&gt; &lt;br /&gt; &lt;/div&gt; </code></pre> <p></p> <p>Please guide me to solve this issue???</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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