Results 1 to 12 of 12

Thread: RESOLVED - Submit button action order?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    149

    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.

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Submit button action order?

    Could you put your code in the Button Click event, rather than the Page Load event?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    149

    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.

  4. #4
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    Re: Submit button action order?

    The Page load event SHOULD fire and tehn the button click event fires.

  5. #5
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Submit button action order?

    Use this in your page load event.
    VB Code:
    1. If Not IsPostBack Then
    2.      'Code you only want to run on page load
    3.  End If

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    149

    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.

  7. #7
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    Re: Submit button action order?

    Quote 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

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    149

    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.

  9. #9
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    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

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    149

    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.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    149

    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.

  12. #12
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    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
  •  



Click Here to Expand Forum to Full Width