|
-
Jul 8th, 2005, 02:44 PM
#1
Thread Starter
Addicted Member
RESOLVED - Submit button action order?
I have this form and on this form are hidden HTML fields that hold values for the current displayed form.
Upon submit, lately I have noticed that the Page_Load event will fire BEFORE the submit_click event. Is this right, am I doing something wrong, because I do not remember it doing this before. This is a problem because of the postback that occurs now the hidden fields have no values when it finally gets around to running the submit_click event.
I just noticed this recently, does anyone have any suggestions, or is this the natural order of the jungle, or am i just doing things completely wrong.
Thanks again.
Last edited by token; Jul 15th, 2005 at 03:33 PM.
-
Jul 8th, 2005, 03:17 PM
#2
Re: Submit button action order?
Could you put your code in the Button Click event, rather than the Page Load event?
-
Jul 8th, 2005, 03:37 PM
#3
Thread Starter
Addicted Member
Re: Submit button action order?
the code is in the button click event, the page_load event just fires when the button is clicked which is the strangest, because it fires before the button_click event.
-
Jul 8th, 2005, 03:52 PM
#4
PowerPoster
Re: Submit button action order?
The Page load event SHOULD fire and tehn the button click event fires.
-
Jul 8th, 2005, 05:06 PM
#5
Re: Submit button action order?
Use this in your page load event.
VB Code:
If Not IsPostBack Then
'Code you only want to run on page load
End If
-
Jul 11th, 2005, 09:28 AM
#6
Thread Starter
Addicted Member
Re: Submit button action order?
That's no good if the page_load does fire before the button_click, I was certain that it wasn't doing that before, because I have code in the button click event that requires information from HTML controls not asp controls to do it's purpose, but if page_load fires before the button-click then the HTML controls lose their state and the information they contained is lost, which wasn't a problem before.
-
Jul 11th, 2005, 10:43 AM
#7
PowerPoster
Re: Submit button action order?
 Originally Posted by token
That's no good if the page_load does fire before the button_click, I was certain that it wasn't doing that before, because I have code in the button click event that requires information from HTML controls not asp controls to do it's purpose, but if page_load fires before the button-click then the HTML controls lose their state and the information they contained is lost, which wasn't a problem before.
So, I guess ASP.NET has changed and now the page_load fires first and then the cached events Just kidding.
Its always been this way.
You just have to put the Page.IsPostBack IF clause just like Bill suggested and the page controls will MAINTAIN their state.
BTW: IF you just tells what EXACTLY you are trying to do, either by actually telling us the scenario or posting some code, then peeps here would actully be able to solve your problem
-
Jul 11th, 2005, 11:40 AM
#8
Thread Starter
Addicted Member
Re: Submit button action order?
You are right, I should detail my scenario a lot more clearly.
The exact scenario is:
1. user opens a form.
2. to enter some of the information requires a popup window, that is tied to another table, that the user makes a selection from.
3. the information for their selection is returned to the original form using javascript.
4. some of this information, the user is not required to know. (record id's, email addies, etc.) so that information is stored in HTML hidden fields.
5. After they have input all their information into this form they submit it, by clicking an asp button Submit
6. Now, the submit still works fine. a record is still added to the
database.
The problem is now all the hidden fields have no values, though before they did before, I obviously changed something or messed something up because, i thought it would go to the click event first and then to the page_load event. after the server has had it's way with the information from the form, because it would have to after the postback of all the information.
I guess I was wrong about the whole thing, but I dont understand what I would put in the if page.isnotpostback for the submit button. I have that clause already in there, but for other things such as dropdownlist population, class instantiations, and whatnot.
What would i put in there to prevent the clearing of my HTML controls.
-
Jul 11th, 2005, 12:54 PM
#9
PowerPoster
Re: Submit button action order?
I guess I was wrong about the whole thing, but I dont understand what I would put in the if page.isnotpostback for the submit button. I have that clause already in there, but for other things such as dropdownlist population, class instantiations, and whatnot
it should be
Code:
If not Page.IsPostBack then
'Code to fill the comboxes,tables,etc on the page
End if
Posting your code would help
-
Jul 12th, 2005, 08:36 AM
#10
Thread Starter
Addicted Member
Re: Submit button action order?
I had the:
If not page.ispostback
'code to fill my comboboxes
end if
I forgot the 'not' in my last post.
but thats not the problem,
I dont know if you want to see all the code in my submit button, all it does is pass all the values from the form to another class that will then write it out to the database.
The problem is that the HTML controls contain no state when the form is postedback, which they would, but i believe it should work like this:
1. when the user clicks the submit button the form will get sent back to the server.
2. the button_click event should now fire acting on the values sent back to the server.
3.after all processing is done it may now either go to a redirected page, as it should in my code.
4. and then there in the redirected page the page_load will fire because a page is being sent back to the user
5. even if i did not have a redirect, it would run the page_load event now of the current form, but not before the button_click.
It just doesnt make sense.
-
Jul 15th, 2005, 11:27 AM
#11
Thread Starter
Addicted Member
Re: Submit button action order?
You were right veryjonny, I was quite wrong about the whole thing. The page_load will run before the button_click. I am still unsure as to why, but this is how it goes.
It turns out my problem was something small and stupid, but I cant remember what. I fixed a couple of days ago and forgot to reply about to what it was.
Again, thanks for your help.
-
Jul 15th, 2005, 03:10 PM
#12
PowerPoster
Re: Submit button action order?
thats good Mark the thread as RESOLVED - I guess you know the shortcut for it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|