By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,231 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,231 IT Pros & Developers. It's quick & easy.

Page_Load fired twice via ProcessRequest

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.