Results 1 to 13 of 13

Thread: page_unload does something else then i expected

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Location
    Gent
    Posts
    166

    page_unload does something else then i expected

    Hello,

    I have some asp.net page with save-buttons. When the save-button is pressed the inputted data in the form is saved to sql-db.

    I think my application would look a lot nicer if the form would be saved automatically when i go to another page.

    I thought copying the code to the "unload-event" of the page would do that for me but apparently it does not. I tried al the page-events that i know of and still don't know what event is raised when you close a page...

    any help? this can't be too tough i hope...

    thanks in advance,
    never argue with an idiot, he will bring you down to his level and will beat you through experience

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

    Re: page_unload does something else then i expected

    How does the person go to the next page?

    Using Page.IspostBack might help in the page_load event.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: page_unload does something else then i expected

    The other way to go to a page would be through a link. Set your save code in the link's click event.

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

    Re: page_unload does something else then i expected

    frog, whats sandpaper?

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: page_unload does something else then i expected

    The solution to all the world's problems!

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Location
    Gent
    Posts
    166

    Re: page_unload does something else then i expected

    thanks for your reply.

    I use a framework and the links to the other pages are all in the left frame, the frame that has to be saved is in the right. i can't call the save-function from the left without reviewing a lot of code...

    is there no base class events like "load" or "disposed" or "init" that would trigger when the user leaves the page?
    never argue with an idiot, he will bring you down to his level and will beat you through experience

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Location
    Gent
    Posts
    166

    Re: page_unload does something else then i expected

    Quote Originally Posted by demoti
    I use a framework

    i meant frameset: i redirect with frameredirect(me, "urlstring")
    never argue with an idiot, he will bring you down to his level and will beat you through experience

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

    Re: page_unload does something else then i expected

    I dont think so that you would be able to find any such event. In asp the page_unload is called when the page is sent to the browser unlike windows forms.

  9. #9
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: page_unload does something else then i expected

    You may be able to do this with java script in the client side.

    When you gert a PM on VBF do you notice how when you try to navigate away from the PM page, or close IE down, you get a message box asking if you want to send a reciept. All you would do is save your code here...you could even use remoting.

    Check out the source code for a PM page.
    When you read this let me know, and I'll send u a PM, so you can check it out.

    Woka

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Location
    Gent
    Posts
    166

    Re: page_unload does something else then i expected

    thanks for your replys,

    although i was hoping there was an event, i'll try to find out what happens when wokawidget sends me an email...

    i'll be posting my findings here, but i kinda have a virus-outbreak inhere so it'll be more probably tomorrow...
    never argue with an idiot, he will bring you down to his level and will beat you through experience

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Location
    Gent
    Posts
    166

    Re: page_unload does something else then i expected

    <code>function checkpm(formname)
    {
    if (formname.dopreview != true)
    {

    if (confirm("Request a read receipt for this message?"))
    {
    formname.receipt.value = 1;
    }

    }
    return validatePost(formname, formname.title.value, 0, 2000);
    }
    </script>

    <form action="private.php" method="post" onsubmit="return checkpm(this)" name="vbform" onreset="vB_RESET(this);">

    </code>

    this might be usable but i can't submit the form from an other frame...or can i?

    also i won't be able to read the textboxvalues (etc) from the vbscript...
    never argue with an idiot, he will bring you down to his level and will beat you through experience

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: page_unload does something else then i expected

    You can submit a form from another frame using js like so:

    Code:
    top.frames.targetframename.document.forms.formname.submit();

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Location
    Gent
    Posts
    166

    Re: page_unload does something else then i expected

    better late than never:

    when you try to close the page or navigate to the URL the application will display a messagebox that you will lose data if you go on without saving.

    the key here seemed to be the onbeforeunload event handler

    here is the link: Using ASP.NET to Prompt a User to Save When Leaving a Page.

    all glory to XIII(forums.asp.net) who provided me with this info!
    never argue with an idiot, he will bring you down to his level and will beat you through experience

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