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 asp.net 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)
    Desire:
    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)

    AutoEventWireup="false"

    Page_Load () Handles MyBase.Load
    HandleFormPost(Request)
    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
    validation.


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

  2. =?Utf-8?B?RXJpayBKZW5zZW4=?=

    Teemu Keiski Guest

    Hmm,

    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
    http://blogs.aspadvice.com/joteke
    Teemu Keiski, Jul 19, 2005
    #2
    1. Advertising

  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
    #3
  4. =?Utf-8?B?RXJpayBKZW5zZW4=?=

    Teemu Keiski Guest

    Ah, I see.

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

    Thanks,

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke
    Teemu Keiski, Jul 19, 2005
    #4
  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
    #5
    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. H Branyan

    Page_Load fires twice

    H Branyan, Oct 22, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    668
    H Branyan
    Oct 22, 2003
  2. Jon
    Replies:
    1
    Views:
    11,324
    George Ter-Saakov
    Jan 13, 2004
  3. Jay Douglas
    Replies:
    7
    Views:
    590
  4. =?Utf-8?B?RWQ=?=

    Page_Load fires twice with Mozilla

    =?Utf-8?B?RWQ=?=, Nov 20, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    4,446
    shailpatel83
    Apr 2, 2010
  5. Replies:
    3
    Views:
    980
Loading...

Share This Page