CodeBehind But Not Postback - Page_Load fires twice

G

Guest

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!
 
T

Teemu Keiski

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.
 
G

Guest

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.
 
T

Teemu Keiski

Ah, I see.

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

Thanks,
 
G

Guest

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top