Discussion in 'ASP .Net' started by masoud bayan, Jan 17, 2005.

  1. masoud bayan

    masoud bayan Guest

    Hi ,

    I used your suggested code to replace doPostBack in my application, but it
    seems window.onbeforeunload is called before, window.__doPostBack, so it can
    not change the condition for showing warning message.
    I am using datagrid with links as ButtonColumn but I do not want
    onbeforeunload event called when they are clicked.

    Any suggestion?


    "bruce barker" <> wrote in message
    > 1) could be any control thats supports validation on the page (must not be
    > empty)
    > 2)
    > air code:
    > RegisterStartupScript("postback",@"
    > <script>
    > if (window.__doPostBack) {
    > window.__oldPostBack = window.__doPostBack;
    > window.__doPostBack = function(t, a) {
    > // add custom code here
    > window.__oldPostBack(t,a);
    > }
    > </script>
    > ");
    > -- bruce (
    > "lilfos" <> wrote in message
    > news:...
    > | Thanks Bruce.
    > |
    > | A couple of questions:
    > |
    > | 1. I would need to set a custom validator's "control to validate"
    > | property, right? If so, would that be the DataGrid? The links
    > | themselves are not controls and they are not available at design time.
    > |
    > | 2. How would I replace __doPostBack? I saw a reference to this in
    > | another post and tried things like oldPostBack = __doPostBack;
    > | __doPostBack = myPostBack, but this seemed to have not effect. I
    > | figure those were just interpreted as variable names rather than
    > | function names, so the functions themselves never changed.
    > | Thanks again.
    > |

    here are two approaches

    1) write a custom validator that sets the flag
    2) replace __doPostback with your own routine that sets the flag. note:
    submit buttons donot call __doPostback, so you must also catch the postback
    in the onsubmit handler.

    -- bruce (

    Hi there,

    I have an page with essentially a "don't forget to save" pop-up
    that is called when the user attempts to navigate away from the page.
    The user has the option to cancel and prevent the page from unloading.

    Since the form data is posted back to the server and saved during a
    normal postback, I don't need to prompt unless the user is actually
    going to a different URL or closing the browser. Currently, I get
    around this with a hidden field called hidPromptToSave and by checking
    that in my function that onbeforeunload calls. I configured each
    control that causes a postback to set that value to false, which causes
    the function to exit without prompting.

    This worked when I could add the onclick attribute to the controls in
    the OnInit method in my code behind. Now, however, I have added a
    twist. I added paging to a datagrid and each page link causes a
    postback (naturally). Unfortunately, the page links are anchor tags
    with an href that calls doPostBack. I can't seem to find a way to add
    to the href or onclick attributes of these links. I've tried a whole
    lot of things both client-side and server-side.

    Assuming I won't ever find a way to add attributes to those links, can
    anyone suggest a different way to give a user the chance to save before
    closing or navigating away, but not doing this on postpack? One
    additional restriction is that we don't want to automatically save
    without asking and then let them continue.

    masoud bayan, Jan 17, 2005
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Timothy Kelley

    calling doPostBack not working

    Timothy Kelley, Jul 18, 2003, in forum: ASP .Net
  2. Johno

    doPostBack client-side function

    Johno, Jul 18, 2003, in forum: ASP .Net
    Jul 21, 2003
  3. Matt Petteys
    Matt Petteys
    Aug 14, 2003
  4. jm

    Dopostback Paging Question

    jm, Oct 30, 2003, in forum: ASP .Net
  5. Nathan Burleson

    DoPostBack from Popup (Child) Window

    Nathan Burleson, Jan 15, 2004, in forum: ASP .Net
    Nathan Burleson
    Jan 15, 2004

Share This Page