473,397 Members | 2,116 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,397 software developers and data experts.

Page_Load fired twice via ProcessRequest

Hi All

This seems to be a common problem here, but I've not found a solution
yet to fix it for me.

When I request a page through a browser, the page_load fires once. When
I request the page's code-behind object via a custom handler and the
code-behind object's ProcessRequest method, it fires twice - both times
from the ProcessRequest call, as far as I can tell.

I don't want to use PageParser, as I don't want the resulting HTML from
the entire page - what I want to do is access a custom control and just
get it's rendered output. A fair portion of my code is intepreting form
parameters and creating the code-behind object via reflection, but I'm
assuming that's not the cause of the problem.

Below is the code from the custom IHttpHandler's ProcessRequest method.
I've got the page's AutoEventWireup set to false, I have authentication
set to none, and I've no idea why this is happening. Nothing is pushed
through to Global's Application_Error, and the code-behind's PreRender
event only fires after both Page_Loads have occurred (So not everything
is duplicated?).

So if anyone can point out what I'm doing wrong, or why ProcessRequest
is calling the Page_Load twice and how to avoid it doing so, it would
be greatly appreciated.

Thanks all

Pat Allan

Code:

public void ProcessRequest(HttpContext context)
{
AppDomain tempDomain = AppDomain.CreateDomain("TempDomain",
AppDomain.CurrentDomain.Evidence,
AppDomain.CurrentDomain.BaseDirectory,
AppDomain.CurrentDomain.RelativeSearchPath,
AppDomain.CurrentDomain.ShadowCopyFiles);

NameValueCollection vars = null;
if (context.Request.HttpMethod.Equals("GET"))
vars = context.Request.QueryString;
if (context.Request.HttpMethod.Equals("POST"))
vars = context.Request.Form;

try
{
string path = context.Request.Url.AbsolutePath;
string obj = path.Substring(path.LastIndexOf("/")+1,
path.LastIndexOf(".") - (path.LastIndexOf("/")+1));

Assembly assembly = tempDomain.Load(vars["assembly"]);
object source = assembly.CreateInstance(obj);

((IHttpHandler)source).ProcessRequest(context);

Control ctl =
(Control)source.GetType().GetProperty(vars["ctl"]).GetValue(source,
null);
ctl.RenderControl(new HtmlTextWriter(context.Response.Output));
}
catch (Exception err)
{
context.Response.Write(err.Message);
}
finally
{
AppDomain.Unload(tempDomain);
}
}

Nov 19 '05 #1
0 1917

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

Similar topics

0
by: Funbeat | last post by:
Hi everybody, I'm facing with the following problem (bug ?) : A page is calling another one (export.aspx) for exporting data to excel. The tecnhique used is to create a Excel-MIME stream...
8
by: Andy | last post by:
Visual Studio 2003 web form problem using C#. My Page_Load or OnInit routines seems to be called twice for every post back to the server. I have 2 web forms that produce this behaviour, all of...
2
by: dx | last post by:
I have a simple user control (.ascx) that is dynamically instantiated in the calling aspx page and added to the control tree (within the page_load.) I have checked and the calling page only...
7
by: Nimrod Cohen | last post by:
Hi During the page_load of my Aspx page "http://myMachine/MyWebApp/Quote.aspx" , i write to the response an html that embeds a form with the action pointing out to the same aspx page i.e...
2
by: RAJ | last post by:
Posting this thread again, can somebody please help me with this. Thanks. This event appears to be invoked twice for absolutely no reason on only one of my ASP.Net web user controls. Although...
14
by: V. Jenks | last post by:
I'm a little rusty having not touched .NET for 6 months and I can't remember why Page_Load is happening twice in this code: private void Page_Load(object sender, System.EventArgs e) {...
4
by: Seraph | last post by:
Again, I'm rather new here, so if I fail to follow any etiquette, please forgive me and let me know what I've done wrong, but I think this might interest quite a few people. One of my colleaques...
1
by: Rippo | last post by:
Hi I have a Master page that opens up a db connection, performs a couple of global routines in the page_load event. All of my other web pages in my web app then inherits this Master Page I...
8
by: John Austin | last post by:
I need to understand why if I add a control and use AddHandler to connect its click event, it will work in Page_Load, but not in a Button_Click. The idea is that the user types some data, presses...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.