Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2005

Tip: Looking for answers? Try searching our database.

CodeBehind But Not Postback - Page_Load fires twice

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Erik Jensen - 19 Jul 2005 00:42 GMT
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!
Teemu Keiski - 19 Jul 2005 06:44 GMT
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.

Signature

Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

Erik Jensen - 19 Jul 2005 15:25 GMT
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.    
Teemu Keiski - 19 Jul 2005 15:55 GMT
Ah, I see.

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

Thanks,

Signature

Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

Erik Jensen - 21 Jul 2005 21:16 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.