What Clientside Event can I capture upon Callback completion?

J

John Kotuby

Hi all,

I am converting an ASPX 3.5 page in VB and VS 2008 from the standard
postback to callbacks using an UpdatePanel.
I had originally been adding an onload attribute to the Body tag in the
Master Page, which would call a Javascript function to display a message if
a hidden field contained a value other than a null string.

Well, of course I discovered that the Body onload event only happenned upon
initial load of the page.

I tried adding a client event attribute to the UpdatePanel but I am not
having any success.

Thanks for any help in this matter.
 
B

bruce barker

use ScriptManger.RegisterStartupScript(). it must be attached to a control in
update panel. also unless the hidden field is in the update panel, it will
not be updated with a async postback

-- bruce (sqlwork.com)
 
J

John Kotuby

Thanks for the tips Bruce.

Wow! I hadn't considered the fact that hidden fields outside of the update
panel would not be updated. I usually place my hidden fields near the bottom
of the page and in this case below the update panel.

You just saved me a whole bunch of time trying to track down the "bug" I
would eventually discover.

Thanks again...
 
J

John Kotuby

Hi Bruce...

I found that the best way to ensure your suggested method to work was to
reference the UpdatePanel control itself and call the method statically as
in:

System.Web.UI.ScriptManager.RegisterStartupScript(Me.UpdatePanel1,
Me.UpdatePanel1.GetType(), "jsShowModal", "PageSetup(); ", True)

This worked fine but resulted in my dialog box popping up before the
contents of the UpdatePanel were completely refreshed.

In a forum discussion from 2006 when VS 2008 was in Beta I found this
alternate method to be used in the ASPX page:
----------------------------
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function EndRequestHandler(sender, args)
{
showDialog("From PageRequestManager");
}
---------------------------
http://forums.asp.net/p/1037531/1440930.aspx

This approach allows the dialog to appear after the update panel contents
are completely refreshed. I cant really see a downside to this appoach
because the code always resides on the rendered page. Maybe there is a
problem that I might run into at some point and I will go back to the
System.Web.UI.ScriptManager.RegisterStartupScript. I was wondering if the
StartupScript that is produced actually persists after the first call to
RegisterStartupScript, or if that script is only generated on the page
whenever the method is called from the code-behind. I suppose that is easy
enough to test.

I was also wondering if I called ScriptManager.RegisterStartupScript in the
PreRender event or even later, if the contents of the Update Panel would be
rendered before the dialog appears.

Thanks for your help Bruce.
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top