Fire server side event before client side event

Discussion in 'ASP .Net Web Controls' started by Guest, Mar 17, 2005.

  1. Guest

    Guest Guest

    Hi everyone.

    I have a button to pop up a report in a different window. Since it is a
    popup, I needed to have it run in the client script. However, I need to
    postback to the server before the popup window comes up to save the record.
    What is happening now is that I'm doing the _doPostBack method before the
    window open and then canceling the event after the window open so it won't
    post back again. The problem is that the postback is sent and before it is
    done, the window pops up and the record has not been saved yet. I have
    tried setting a variable that says that it is printed, but the window onload
    only occurs the first time. Does anyone know of a client-side event I can
    hook into that works like the server side Page_Load or Page_Prerender event
    so that I can wait on the popup until the save is done? Or are there any
    other suggestions?

    Thanks,
    MH
    Guest, Mar 17, 2005
    #1
    1. Advertising

  2. Hi MH,

    This is a bit of a hack, but you can output the client-side code only when
    the postback is done. So, you do the server-side stuff and then, as the page
    finishes reloading, do the client-side. Here's a little demo.

    Let us know if it helps?

    Ken
    Microsoft MVP [ASP.NET]
    Toronto

    <form id="Form1" method="post" runat="server">
    <p>
    <asp:label id="Label1" runat="server">Label</asp:label></p>
    <p>
    <asp:button id="Button1" runat="server"
    Text="Button"></asp:button></p>
    </form>

    Private Sub Button1_Click _
    (ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button1.Click
    Label1.Text = "Server-side event done at: " _
    & Now.ToLongTimeString
    Page.RegisterStartupScript("client", _
    "<script>alert('Client event here.');</script>")
    End Sub


    <mh> wrote in message news:...
    > Hi everyone.
    >
    > I have a button to pop up a report in a different window. Since it is a
    > popup, I needed to have it run in the client script. However, I need to
    > postback to the server before the popup window comes up to save the
    > record. What is happening now is that I'm doing the _doPostBack method
    > before the window open and then canceling the event after the window open
    > so it won't post back again. The problem is that the postback is sent and
    > before it is done, the window pops up and the record has not been saved
    > yet. I have tried setting a variable that says that it is printed, but
    > the window onload only occurs the first time. Does anyone know of a
    > client-side event I can hook into that works like the server side
    > Page_Load or Page_Prerender event so that I can wait on the popup until
    > the save is done? Or are there any other suggestions?
    >
    > Thanks,
    > MH
    >
    Ken Cox [Microsoft MVP], Mar 17, 2005
    #2
    1. Advertising

  3. Guest

    Guest Guest

    Ken,

    Thank you so much for giving me this fix! It worked like a charm. It does
    exactly what I need it to do. You are awesome! :)

    MH

    "Ken Cox [Microsoft MVP]" <> wrote in message
    news:...
    > Hi MH,
    >
    > This is a bit of a hack, but you can output the client-side code only when
    > the postback is done. So, you do the server-side stuff and then, as the
    > page finishes reloading, do the client-side. Here's a little demo.
    >
    > Let us know if it helps?
    >
    > Ken
    > Microsoft MVP [ASP.NET]
    > Toronto
    >
    > <form id="Form1" method="post" runat="server">
    > <p>
    > <asp:label id="Label1" runat="server">Label</asp:label></p>
    > <p>
    > <asp:button id="Button1" runat="server"
    > Text="Button"></asp:button></p>
    > </form>
    >
    > Private Sub Button1_Click _
    > (ByVal sender As System.Object, ByVal e As System.EventArgs) _
    > Handles Button1.Click
    > Label1.Text = "Server-side event done at: " _
    > & Now.ToLongTimeString
    > Page.RegisterStartupScript("client", _
    > "<script>alert('Client event here.');</script>")
    > End Sub
    >
    >
    > <mh> wrote in message news:...
    >> Hi everyone.
    >>
    >> I have a button to pop up a report in a different window. Since it is a
    >> popup, I needed to have it run in the client script. However, I need to
    >> postback to the server before the popup window comes up to save the
    >> record. What is happening now is that I'm doing the _doPostBack method
    >> before the window open and then canceling the event after the window open
    >> so it won't post back again. The problem is that the postback is sent
    >> and before it is done, the window pops up and the record has not been
    >> saved yet. I have tried setting a variable that says that it is printed,
    >> but the window onload only occurs the first time. Does anyone know of a
    >> client-side event I can hook into that works like the server side
    >> Page_Load or Page_Prerender event so that I can wait on the popup until
    >> the save is done? Or are there any other suggestions?
    >>
    >> Thanks,
    >> MH
    >>

    >
    Guest, Mar 18, 2005
    #3
  4. Thanks for reporting back! Glad it worked for you!

    Ken

    <mh> wrote in message news:...
    > Ken,
    >
    > Thank you so much for giving me this fix! It worked like a charm. It
    > does exactly what I need it to do. You are awesome! :)
    >
    Ken Cox [Microsoft MVP], Mar 18, 2005
    #4
    1. Advertising

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. moondaddy
    Replies:
    2
    Views:
    1,034
    Steven Cheng[MSFT]
    Jul 16, 2004
  2. Stuart Whiteford
    Replies:
    2
    Views:
    744
    Stuart Whiteford
    Apr 25, 2006
  3. Replies:
    1
    Views:
    717
    Norman Yuan
    Mar 22, 2007
  4. Michal Valent
    Replies:
    2
    Views:
    4,309
    Michal Valent
    Dec 5, 2007
  5. Vili
    Replies:
    5
    Views:
    417
    siccolo
    Feb 19, 2008
Loading...

Share This Page