Monday, March 26, 2012

Execute client script in a async postback

Hi,

I´ve just replaced the july atlas ctp with ajax 1.0. I have a button as part of a UpdatePanel. In the serverside clickevent of the butten I want to call a client script but it doesn´t work. Even a simple alert('test') doesn´t work. I´ve used Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "test", "alert('test');", true); as well as the similar command ScriptManager.RegisterClientScriptBlock. Can anybody help me?


Thx

Hi,

You need to call the new static registration method on ScriptManager to register the script. For the first parameter pass in the button that's inside the UpdatePanel to get its script to be sent down along with the UpdatePanel's new contents.

Thanks,

Eilon


hello.

btw, i have 2 questions about the new methods:

1. what happens if you're aa component developer? i mean, say that you need to support full and partial postbacks so that you allways sent something back to the client side. if you use the the new registerXXX from scriptmanager, you're creating a dependency between your control and ajax extensions. what happens if you don't wont ajax extensions on your app?

2. even though i see the possibilities in associating a script with a control placed inside an updaptepanel (while performing the script registration), what happens when you just need to insert a script back on the page during a partial postback? an example; you have a simple page with an updatepanel and you set the childrenastrigger to false. the objective of the panel is to let you get info from the controls, do some server side processing and then return a script to client (yes, a little off, but it's something that might be used by the old instance page methods fans since there's no instance page methods in the current release). since the chidrenastriggers is set to false, you can't send back a script from the server side (even though you assaociate it with a control inside the updatepanel) because the panel isn't being refreshed and due to that, it won't be included in the page.


More info about script registration in my recent post:http://forums.asp.net/thread/1440058.aspx

Thanks,

Eilon


Finally it works, thanks a lot!

Eilon:

More info about script registration in my recent post:http://forums.asp.net/thread/1440058.aspx

Thanks,

Eilon


hello.


still some questions remain:

1. my controls must always link to the ajax extensions dll even if the pages that use them aren't using ajax

2. i've presented a scenario where i just use an updatepanel to get all the controls on the server side and i need to send back a javascript message to the client. how can i accomplish this (i've set the childrenastrigger to false since i don't want to refresh the panel). if there was an overload for inserting javascript on the page without associating the instruction to a control, it would solve my problem (note that in those cases, i know that there's no chance of cleaning the script but i'd prefer to have that option since most of the time i'll be sending method calls from the server side).


Hi Luis,

1. See another of my recent posts:http://forums.asp.net/thread/1445844.aspx

2. The way I would like to see this implemented is that instead of the page registering the script, the page should add a control to the UpdatePanel and that control should register its own script. Nevertheless, it's a suggestion I've been considering myself. For example maybe if you pass in the Page or something we'll always include the script. I'm just afraid that it's a feature that people will abuse to no end and perhaps cause even more problems than it solves. Definitely under consideration, though.

Thanks,

Eilon


you may also look here:

http://forums.asp.net/thread/1445682.aspx

No comments:

Post a Comment