CodeBehind But Not Postback - Page_Load fires twice

Discussion in 'ASP .Net' started by =?Utf-8?B?RXJpayBKZW5zZW4=?=, Jul 19, 2005.

  1. Hello All,
    I am trying a non-standard approace to that i hope will work so I
    can get an xhtml complient page.

    Setup as Follows:
    Code-behind but not form runat="server" so traditional Request.Form("key")
    handling of the POST event. No server-controls (only html elements)
    Not to have to code-inside.

    What's occuring on POST events (and I do not have many forms on my site so
    this is a nice-to-have answer)


    Page_Load () Handles MyBase.Load
    end Sub

    Sub(objRequest as HttpRequest)

    Do form processing

    end sub

    Soo.. with that setup info. I put breakpoints in my OnLoad and its running
    twice and has the whole form collection on both times around so I can't go..
    if request.form("key").Length = 0 or something like that.

    Has anyone used the same set-up of not form-runat="server" so you can get
    valid xhtml pages? i.e. the viewstate is not-self-closing so it breaks my

    Thanks to all!
    =?Utf-8?B?RXJpayBKZW5zZW4=?=, Jul 19, 2005
    1. Advertisements

  2. Teemu Keiski

    Teemu Keiski Guest


    seems normal to me as Load event fires always once during a request (once
    for the initial request and then once per postback).

    You could use Page.IsPostBack property to check whether it is a postback or
    not and that way run your logic.

    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    Teemu Keiski, Jul 19, 2005
    1. Advertisements

  3. Because I am not using postback and <form runat="server" the IsPostBack
    property is always false.

    when I mean it runs twice I mean:

    _Load method runs once on initial rendering of page.

    user fills out form, and clicks html <button or <input type="submit"

    codebehind enters _Load which calls a function (inside that function is one
    of two redirects depending on a boolean state, one-redirects back to same
    page, two-redirects to a second page.

    The code goes through, hits the redirect line, but then goes back up into
    the same page's _Load, and runs through again. Only on the second time
    hitting the redirect code does the page actually go to the redirect location.

    It's strange.
    =?Utf-8?B?RXJpayBKZW5zZW4=?=, Jul 19, 2005
  4. Teemu Keiski

    Teemu Keiski Guest

    Ah, I see.

    Can you provide a small snippet which would demonstrate it? It's easier to
    repro that way.


    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    Teemu Keiski, Jul 19, 2005
  5. Teemu,
    I appologize, looks like it was my fault. But it was baffling at first
    because this was happening when browsing the page in IE only.

    what I had done was an onsubmit validator for the form was bound.. but
    instead of just returning true in the validator if success, it was calling
    form.submit() and therefore, in IE the form appeared to post twice but in
    other browsers it posted once. I found this quite odd but have corrected
    the JS and it resolved the issue.

    Thank you for taking the time to answer my earlier post.
    =?Utf-8?B?RXJpayBKZW5zZW4=?=, Jul 21, 2005
    1. Advertisements

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. H Branyan

    Page_Load fires twice

    H Branyan, Oct 22, 2003, in forum: ASP .Net
    H Branyan
    Oct 22, 2003
  2. Jon
    George Ter-Saakov
    Jan 13, 2004
  3. Jay Douglas
  4. =?Utf-8?B?RWQ=?=

    Page_Load fires twice with Mozilla

    =?Utf-8?B?RWQ=?=, Nov 20, 2004, in forum: ASP .Net
    Apr 2, 2010
  5. Replies: