Page_Load fired twice via ProcessRequest

Discussion in 'ASP .Net' started by pat.allan@gmail.com, Jun 23, 2005.

  1. Guest

    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);
    }
    }
    , Jun 23, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bminder
    Replies:
    1
    Views:
    2,147
    nfedin
    Feb 23, 2004
  2. =?Utf-8?B?Tmltcm9kIENvaGVu?=

    Page_Load being fired twice

    =?Utf-8?B?Tmltcm9kIENvaGVu?=, May 27, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    724
    Steven Cheng[MSFT]
    Jun 9, 2004
  3. RAJ

    PAGE_LOAD fired twice

    RAJ, Jun 8, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,906
  4. Rippo
    Replies:
    1
    Views:
    500
    Scott Allen
    Aug 17, 2005
  5. rockdale
    Replies:
    1
    Views:
    640
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Nov 16, 2006
Loading...

Share This Page