473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

LoadControl in Global.asax.cs

I want to user the Page method LoadControl inside the Global.asax.cs
but when I instantiate a page and try it I get the following error...

System.NullReferenceException: Object reference not set to an instance
of an object. at System.Web.UI.UserControlParser.GetCompiledUserCon trolType(String
virtualPath, String inputFile, HttpContext context) at
System.Web.UI.TemplateControl.LoadControl(String virtualPath) at
tt360.Cms.Adm.Global.Timer_Elapsed(Object sender, ElapsedEventArgs e)
in c:\vss\tt3\cms\004\web\tt360.cms.adm\global.asax.c s:line 95

I guess this is becuase the HttpContent is null. Now is there anyway I
can get round this?

Thanks,

Rob.
Nov 18 '05 #1
3 2991
Robert Walter wrote:
I want to user the Page method LoadControl inside the Global.asax.cs
but when I instantiate a page and try it I get the following error...

System.NullReferenceException: Object reference not set to an instance
of an object. at System.Web.UI.UserControlParser.GetCompiledUserCon trolType(String
virtualPath, String inputFile, HttpContext context) at
System.Web.UI.TemplateControl.LoadControl(String virtualPath) at
tt360.Cms.Adm.Global.Timer_Elapsed(Object sender, ElapsedEventArgs e)
in c:\vss\tt3\cms\004\web\tt360.cms.adm\global.asax.c s:line 95

I guess this is becuase the HttpContent is null. Now is there anyway I
can get round this?


Global.asax is for application level events - there's no page to load a
control into.

What overall result are you looking for?

--
mikeb
Nov 18 '05 #2
mikeb <ma************@nospam.mailnull.com> wrote in message news:<ea*************@TK2MSFTNGP10.phx.gbl>...
Robert Walter wrote:
I want to user the Page method LoadControl inside the Global.asax.cs
but when I instantiate a page and try it I get the following error...

System.NullReferenceException: Object reference not set to an instance
of an object. at System.Web.UI.UserControlParser.GetCompiledUserCon trolType(String
virtualPath, String inputFile, HttpContext context) at
System.Web.UI.TemplateControl.LoadControl(String virtualPath) at
tt360.Cms.Adm.Global.Timer_Elapsed(Object sender, ElapsedEventArgs e)
in c:\vss\tt3\cms\004\web\tt360.cms.adm\global.asax.c s:line 95

I guess this is becuase the HttpContent is null. Now is there anyway I
can get round this?


Global.asax is for application level events - there's no page to load a
control into.

What overall result are you looking for?


Basically I'm using the Global.asax.cs to run timed application
events, sending out emails. The emails I want to send out are the
output from UserControls on the site.

I can get standard ASP.NET controls to generate fine but when I do a
LoadControl it gives the above error. Now I'm sure what I'm trying is
possible as Paul Wilsons Application Keep Alive Article
(http://authors.aspalliance.com/paulw...rticles/?id=12) does a
LoadControl to compile user controls throughout a site.

The code I'm running is...

MailMessage mailMessage = new MailMessage();

mailMessage.From = "te**@test.com";
mailMessage.To = "te**@test.com";
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Html;

string html = "html";
string subject = "subject";

try
{
System.Web.UI.Page controlLoader = new System.Web.UI.Page();

System.Web.UI.Control control =
controlLoader.LoadControl("~/Emails/test.ascx");

StringWriter writer = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);

control.RenderControl(htmlWriter);

html = htmlWriter.InnerWriter.ToString();
subject = "subject";
}
catch (Exception ex)
{
html = ex.ToString();
}

mailMessage.Subject = subject;
mailMessage.Body = html;

System.Web.Mail.SmtpMail.SmtpServer = "mailserver";
System.Web.Mail.SmtpMail.Send(mailMessage);
And test.ascx is simply

<%@ Control Language="C#" %>
<asp:label runat="server" id="Test" Text="test"></asp:label>
Thanks in advance for your help,

Rob.
Nov 18 '05 #3
Robert Walter wrote:
mikeb <ma************@nospam.mailnull.com> wrote in message news:<ea*************@TK2MSFTNGP10.phx.gbl>...
Robert Walter wrote:
I want to user the Page method LoadControl inside the Global.asax.cs
but when I instantiate a page and try it I get the following error...

System.NullReferenceException: Object reference not set to an instance
of an object. at System.Web.UI.UserControlParser.GetCompiledUserCon trolType(String
virtualPath, String inputFile, HttpContext context) at
System.Web.UI.TemplateControl.LoadControl(Strin g virtualPath) at
tt360.Cms.Adm.Global.Timer_Elapsed(Object sender, ElapsedEventArgs e)
in c:\vss\tt3\cms\004\web\tt360.cms.adm\global.asax.c s:line 95

I guess this is becuase the HttpContent is null. Now is there anyway I
can get round this?


Global.asax is for application level events - there's no page to load a
control into.

What overall result are you looking for?

Basically I'm using the Global.asax.cs to run timed application
events, sending out emails. The emails I want to send out are the
output from UserControls on the site.

I can get standard ASP.NET controls to generate fine but when I do a
LoadControl it gives the above error. Now I'm sure what I'm trying is
possible as Paul Wilsons Application Keep Alive Article
(http://authors.aspalliance.com/paulw...rticles/?id=12) does a
LoadControl to compile user controls throughout a site.

The code I'm running is...

.... snip ...

I see that you're creating your own page to load the control into.

However, when I cut-n-paste your code into a new project and run it, I
do not get an exception.

I'm using VS.NET 2003, in case that matters.
--
mikeb
Nov 18 '05 #4

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

Similar topics

22
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to...
12
by: John M | last post by:
Hello, On Microsoft Visual Studio .NET 2003, I want to use some global elements, that can be used in each one of my pages. i.e I put a oleDBConnection on global.asax.vb How can I use it...
8
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical...
5
by: ad | last post by:
The Global.asax is code-inside with default. How to change Global.asax to code-behind?
11
by: Ron | last post by:
I have a web project compiled with the new "Web Deployment Projects" plugin for VS2005. I'm deploying the web project to one assembly and with updateable option set to ON. When I'm running the...
4
by: Al Santino | last post by:
Hello, I've created a simple C# web services project using Visual Studio 2005. My service compiles and runs correctly when called by remote clients. I'm able to step through the service in the...
16
by: thefritz_j | last post by:
We just converted our VS2003 1.1 VB web project (which was working fine) to VS2005 2.0 and now I get: Parser Error Message: Could not load type '<Namespace>.'. Source Error: Line 1: <%@...
8
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project...
15
by: =?Utf-8?B?UGF0Qg==?= | last post by:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax code file. In 1.1 I could have a code behind file for the global.asax file. This allow for shared variables of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.