Fire server side event before client side event

G

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
 
K

Ken Cox [Microsoft MVP]

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
 
G

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 said:
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


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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top