473,670 Members | 2,636 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object reference error in UserControl's Load event

I have a UserControl that I declare programmaticall y as follows:

Dim userctrl as New rightside_porta l()

The codebehind file for this UserControl looks like the following:

Partial Public Class rightside_porta l : Inherits System.Web.UI.U serControl

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
Handles Me.Load

Const renewurl As String = "http://www.renewingsit e.com/"

Me.lblExpiresOn .Text = String.Format(" IMPORTANT<br/>Your account is set to
expire {0}. To renew your membership, please ", "EXPIRATIONDATE ")

Me.lnkRenew.Nav igateUrl = renewurl

Me.lnkSaveToday .NavigateUrl = renewurl

End Sub

End Class
However, I receive the following error when I run the application:

Server Error in '/' 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.NullRefe renceException: Object reference not set
to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceEx ception: Object reference not set to an instance of an
object.]
AFBE.rightside_ portal.Page_Loa d(Object sender, EventArgs e) +59
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +99
System.Web.UI.C ontrol.LoadRecu rsive() +47
System.Web.UI.C ontrol.LoadRecu rsive() +131
System.Web.UI.C ontrol.LoadRecu rsive() +131
System.Web.UI.C ontrol.LoadRecu rsive() +131
System.Web.UI.C ontrol.LoadRecu rsive() +131
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +1061

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.507 27.42; ASP.NET
Version:2.0.507 27.210

I am pretty sure the problem has something to do with the fact that I am
declaring the UserControl in my codebehind rather than my *.aspx file, but I
am not quite sure what I need to do differently. If anyone can help me, I
would appreciate it. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Jan 6 '07 #1
1 4212
you can't create a "new UserContorl();"

you need to use Page.LoadContro l("~/controls/test.ascx");

Using "new" creates a new instance of the class, but doesn't instanticate
the aspx class. therefore lblExpires is never created and you end up with a
null reference.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Nathan Sokalski" <nj********@hot mail.comwrote in message
news:Oi******** *****@TK2MSFTNG P06.phx.gbl...
>I have a UserControl that I declare programmaticall y as follows:

Dim userctrl as New rightside_porta l()

The codebehind file for this UserControl looks like the following:

Partial Public Class rightside_porta l : Inherits System.Web.UI.U serControl

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load

Const renewurl As String = "http://www.renewingsit e.com/"

Me.lblExpiresOn .Text = String.Format(" IMPORTANT<br/>Your account is set to
expire {0}. To renew your membership, please ", "EXPIRATIONDATE ")

Me.lnkRenew.Nav igateUrl = renewurl

Me.lnkSaveToday .NavigateUrl = renewurl

End Sub

End Class
However, I receive the following error when I run the application:

Server Error in '/' 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.NullRefe renceException: Object reference not set
to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceEx ception: Object reference not set to an instance of an
object.]
AFBE.rightside_ portal.Page_Loa d(Object sender, EventArgs e) +59
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +99
System.Web.UI.C ontrol.LoadRecu rsive() +47
System.Web.UI.C ontrol.LoadRecu rsive() +131
System.Web.UI.C ontrol.LoadRecu rsive() +131
System.Web.UI.C ontrol.LoadRecu rsive() +131
System.Web.UI.C ontrol.LoadRecu rsive() +131
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +1061

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.507 27.42;
ASP.NET Version:2.0.507 27.210

I am pretty sure the problem has something to do with the fact that I am
declaring the UserControl in my codebehind rather than my *.aspx file, but
I am not quite sure what I need to do differently. If anyone can help me,
I would appreciate it. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Jan 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3013
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have access to the methods and properties from the Page_Load, no problem there. But as soon as I want access to the user control from another procedure on the same page, I get the next error message: "Object reference not set to an instance of an...
1
1215
by: AC | last post by:
I have a page class that inherits the System.Web.UI.Page class. Essentially what it does is load a user profile from a session (if it isn't loaded, it loads it into the session) and exposes it via a public property. This works just fine. I have user controls that require the profile as well and I was coding it to work in the same way (created a class that inherits the System.Web.UI.UserControl class. It does the exact same thing as the...
9
2172
by: Moe Sizlak | last post by:
Hi There, I am trying to write the selected value of a listcontrol when a button is clicked and I keep getting the error "object not set to a reference of an object". The libox itself is in a usercontrol and all i'm really needing to do is get the selected value when the button is clicked on the form. Can someone tell what I need to include in my page to get this working ? Moe <><
1
3453
by: Tim | last post by:
Greetings! I have a UserControl. On this UserControl is a Panel and a RadioButtonList. The Panel's Visible property is set to false by default. When the user selects a particular RadioButtonList value, a postback is performed and the Panel's Visible property is set to true. Selecting a different RadioButtonList value sets the Visible property to false again. So far, so good. It does, in fact, do this.
2
5304
by: Giovanni Bassi | last post by:
Hello All, I have encountered a problem. I am using visual inheritance and my base form adds an event handler on Form Load using the AddHandler Keyword. The problem is that if the Event Handler code is there, when I create the inherited form I get the error "Object Reference not set to an instance of an object". If it is not I get no error. I have tried leaving this code in the forms Sub New, but it produces the
9
14442
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem is that the webcontrols get created on the OnLoad event of the usercontrol and the event handlers are assigned at the same time. I have to click twice on the controls for the events to be raised, the first time nothing...
3
4311
by: j-in-uk | last post by:
I have 3 pages Site.master, Album.aspx and ContinentsMenu.ascx. Continents is a usercontrol placed in Albums. In Album.aspx.cs I need to access a property from the Continents usercontrol and is done using the code below. When I add masterpages to Album.aspx and remove all the html tags I get the error System.NullReferenceException: Object reference not set to an instance of an object. for the highlighted yellow line below. I notice once I...
1
1574
by: Nathan Sokalski | last post by:
I have a UserControl that I declare programmatically as follows: Dim userctrl as New rightside_portal() The codebehind file for this UserControl looks like the following: Partial Public Class rightside_portal : Inherits System.Web.UI.UserControl Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
2
3067
by: =?Utf-8?B?R2FuZXNhbiBzZWx2YXJhag==?= | last post by:
Hi We are using .net 1.1 on windows 2003 server. This is we are facing in our production server. When we are doing the load testing we are getting the bellow error. While the load testing this error is not coming frequently. When we run 20 threads for 3 mins we are getting this error message 2 or 3 times. But this line of code is executed by all the threads. Please any one face this problem earlier kindly tell me how you could solve...
0
8468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8901
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4209
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4390
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2041
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.