Submit and Page_Load problems

joe_pool_is

Contributor
Joined
Jan 18, 2004
Messages
507
Location
Longview, TX [USA]
Whenever I start my web application, it runs through the Page_Load subroutine twice. Why twice? I only want it to execute this portion once.

Then, whenever I click the SUBMIT button, again my code runs executes the Page_Load subroutine twice before dropping down to the SUBMIT.Click routine. This causes all of my form's data to be lost!

Could someone please help? I am very confused. (Yes, the SUBMIT button is an ASP control with an event handler.)
 
Could you post the code from the page - it makes it a lot easier for people to help if they have something to look at....
Also in your aspx page what <@ > tags have you got at the top of the page?
 
PlausiblyDamp,

YES, YES! I am happy to show you my code!!! :) In fact, I have taken the whole darned project and zipped it up into the aspnet-client.zip file.

If you can tell me anything, I would really, really appreciate it. I've got deadlines creaping up on me, and no one up here at work knows what the problem with that is.

Note: There are still bugs in the SignUp.aspx form, especially in the SQL statements. I'm working on those, too. As soon as I get this Page_Load problem fixed, I'll get back to debugging my SQL issues.
 

Attachments

Last edited by a moderator:
The problem is down to two things
In your aspx page within the <@Page > declaration you have AutoEventWireup = true set. This causes the framework to automatically invode the function named Page_Load on startup.
You also have the Handles MyBase.Load declaration at the end of the page load function - this also causes the framework to invoke the page_load event.
Hence it fires twice, either remove the handles mybase.load or set AutoEventWireup to false and the problem shoud go away.
 
PlausiblyDamp,

I got the AutoEventWireup=false part set. I believe that was mistakenly set while trying to debug the application earlier.

As for the "Handles MyBase.Load" declaration at the end of the page load function, isn't this required by .NET? I tried removing that piece, but now the load portion does not execute at all. How do I work around that?

Thanks for your help, too!
 
Last edited:
You removed AutoEventWireup to false and removed that line of code; nothing will execute! You have to have one or the other; not both, not none... That is unless you don't want anything happening at load. That's what Plaus was trying to tell you earlier.
 
The SignUp.aspx form still does it.

First, I set AutoEventWireup="false" and included the "Handles MyBase.Load" the next time I tried it the other way. Both times it still messes up.

When I click Submit, it goes to the Page_Load function and skips over the "If Not Page.IsPostback Then". Then, it immediately runs Page_Load again, but this time it *does* go into the "If Not Page.IsPostback Then" section of my code.

What is going on? Should I just restart from scratch?
 
I have been spending more hours trying to debug this, and I have noticed something that may mean something:

My form uses ICollections to populate State and date fields. I have noticed that if I try simply clicking the "Submit" button *without* filling in any of the fields on the form, my program goes straight to the "Submit.Click" subroutine, instead of going to the "Page.Load" subroutine first.

Does this help? Does this clue offer any insight? Is there something about selecting an item in an ICollection that tells the form to go through the "Page.Load" subroutine? If so, how could I eliminate this?
 
Still need help on this, please.

I noticed while debugging that there are these freaky "anonymous code" files that are showing up in my signup.aspx form. What are these? Are these causing my problems? (See attachment Image2.gif)
 

Attachments

If anyone is still curious about this, the case is closed. It was a boneheaded mistake. At some point along the way, I tried to make it so that one of the CheckBoxes would call Server.Transfer() back to itself. With the CheckBox checked every time, this was causing the Page_Load to fire. I had the hardest time figuring that out, though. I even re-wrote the entire webpage, but copied in my VB.NET code (which imported the same error into my new page - Agh!)

Thanks to everyone that contributed and spent time looking for my goof-ups.
 
Back
Top