|
|
|
start date: Tue, 21 Aug 2007 15:06:51 -0700,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
Lit
|
|
2
Braulio Diez
|
|
3
Lit
|
|
4
Lit
|
|
5
Lit
|
|
6
Braulio Diez
|
Hook to AJAX End Event on Client Side
Hi,
I would like to run some dynamic-JavaScript code at the end of a callback of
an AJAX Call. for an update Panel
1---I click on a button on the browser,
2---AJAX method called server
3---some AJAX method get data from server , browser renders new info + send
some JavaScript code with it.
4---Then after that I would like to run a client side JavaScript code that
came with the AJAX callback data.
I tried to Register a Startup JavaScript code but it does not run within
AJAX ??
Any Ideas??
Thank You,
Lit
Date:Tue, 21 Aug 2007 15:06:51 -0700
Author:
|
RE: Hook to AJAX End Event on Client Side
Hello,
Take a look at InitializeRequest and EndRequest (on end request you can
check which update panel triggered the petition and then run your javascript):
http://asp.net/ajax/documentation/live/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerInitializeRequestEvent.aspx
A sample code (this one is used to show and hid progress indicators when
they are associated to a panel ID, ** bug on AJAX**):
<script type="text/javascript">
// Well... UpdateProgress only works fine with triggers if it's not
associated to a single update panel
// to make it work with a single panel (like the case we have in this
case), we need to make a hack
// intercept the call, check the control name (response.write needed
from server because of the nasty
// ctl_00 prefix added to the control), and then show the progress
indicator associated to that control
// very ugly stuff, but we only will need it if we have two update
panles and two progress indicators.
// http://geeks.ms/blogs/sergiotarrillo/archive/2007/05/06/14266.aspx
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
var postBackElement;
function InitializeRequest(sender, args) {
if (prm.get_isInAsyncPostBack())
{
args.set_cancel(true);
}
postBackElement = args.get_postBackElement();
// Dotnet panel
if (postBackElement.id ==
'<%Response.Write(btdotnetSearchFilter.ClientID.ToString());%>')
{
$get('<%Response.Write(UpdateProgressNet.ClientID.ToString());%>').style.display = "block";
}
// SQL Server Panel
if (postBackElement.id ==
'<%Response.Write(btnSQLServerfilter.ClientID.ToString());%>')
{
$get('<%Response.Write(UpdateProgressSQL.ClientID.ToString());%>').style.display = "block";
}
}
function EndRequest (sender, args) {
if (postBackElement.id ==
'<%Response.Write(btnSQLServerfilter.ClientID.ToString());%>')
{
$get('<%Response.Write(UpdateProgressSQL.ClientID.ToString());%>').style.display = "none";
}
}
function AbortPostBack() {
if (prm.get_isInAsyncPostBack()) {
prm.abortPostBack();
}
}
</script>
Good luck
Braulio
/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------
"Lit" wrote:
> Hi,
>
> I would like to run some dynamic-JavaScript code at the end of a callback of
> an AJAX Call. for an update Panel
>
> 1---I click on a button on the browser,
> 2---AJAX method called server
> 3---some AJAX method get data from server , browser renders new info + send
> some JavaScript code with it.
> 4---Then after that I would like to run a client side JavaScript code that
> came with the AJAX callback data.
>
> I tried to Register a Startup JavaScript code but it does not run within
> AJAX ??
>
> Any Ideas??
>
> Thank You,
>
> Lit
>
>
>
>
>
>
>
>
>
Date:Tue, 21 Aug 2007 23:22:18 -0700
Author:
|
Re: Hook to AJAX End Event on Client Side
Hi Braulio,
Excellent.
You guided me in the right direction. I am looking into the events.
I need to figure out, best way and all, how to send extra data.. etc..
Thank you for you help.
Lit
"Braulio Diez" wrote in message
news:DBA29477-F33D-4251-9470-B96968EBA03D@microsoft.com...
> Hello,
>
> Take a look at InitializeRequest and EndRequest (on end request you can
> check which update panel triggered the petition and then run your
> javascript):
>
> http://asp.net/ajax/documentation/live/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerInitializeRequestEvent.aspx
>
> A sample code (this one is used to show and hid progress indicators when
> they are associated to a panel ID, ** bug on AJAX**):
>
> <script type="text/javascript">
> // Well... UpdateProgress only works fine with triggers if it's not
> associated to a single update panel
> // to make it work with a single panel (like the case we have in this
> case), we need to make a hack
> // intercept the call, check the control name (response.write needed
> from server because of the nasty
> // ctl_00 prefix added to the control), and then show the progress
> indicator associated to that control
> // very ugly stuff, but we only will need it if we have two update
> panles and two progress indicators.
> // http://geeks.ms/blogs/sergiotarrillo/archive/2007/05/06/14266.aspx
> var prm = Sys.WebForms.PageRequestManager.getInstance();
> prm.add_initializeRequest(InitializeRequest);
> prm.add_endRequest(EndRequest);
> var postBackElement;
>
> function InitializeRequest(sender, args) {
> if (prm.get_isInAsyncPostBack())
> {
> args.set_cancel(true);
> }
> postBackElement = args.get_postBackElement();
> // Dotnet panel
> if (postBackElement.id ==
> '<%Response.Write(btdotnetSearchFilter.ClientID.ToString());%>')
> {
>
> $get('<%Response.Write(UpdateProgressNet.ClientID.ToString());%>').style.display
> = "block";
> }
>
> // SQL Server Panel
> if (postBackElement.id ==
> '<%Response.Write(btnSQLServerfilter.ClientID.ToString());%>')
> {
>
> $get('<%Response.Write(UpdateProgressSQL.ClientID.ToString());%>').style.display
> = "block";
> }
>
> }
> function EndRequest (sender, args) {
> if (postBackElement.id ==
> '<%Response.Write(btnSQLServerfilter.ClientID.ToString());%>')
> {
>
> $get('<%Response.Write(UpdateProgressSQL.ClientID.ToString());%>').style.display
> = "none";
> }
> }
> function AbortPostBack() {
> if (prm.get_isInAsyncPostBack()) {
> prm.abortPostBack();
> }
> }
> </script>
>
>
> Good luck
> Braulio
>
> /// ------------------------------
> /// Braulio Diez
> ///
> /// http://www.tipsdotnet.com
> /// ------------------------------
>
>
>
>
> "Lit" wrote:
>
>> Hi,
>>
>> I would like to run some dynamic-JavaScript code at the end of a callback
>> of
>> an AJAX Call. for an update Panel
>>
>> 1---I click on a button on the browser,
>> 2---AJAX method called server
>> 3---some AJAX method get data from server , browser renders new info +
>> send
>> some JavaScript code with it.
>> 4---Then after that I would like to run a client side JavaScript code
>> that
>> came with the AJAX callback data.
>>
>> I tried to Register a Startup JavaScript code but it does not run within
>> AJAX ??
>>
>> Any Ideas??
>>
>> Thank You,
>>
>> Lit
>>
>>
>>
>>
>>
>>
>>
>>
>>
Date:Wed, 22 Aug 2007 08:58:14 -0700
Author:
|
Re: Hook to AJAX End Event on Client Side
Hi Braulio,
I am able to hook the EndRequestHandler and it is being Fired but I am
unable to pass any args to it.
I tried to use something like this
if (ScriptManager1.IsInAsyncPostBack) // in code behind.
{
ScriptManager1.RegisterDataItem(Label2, "My extra data to pass"); // this
is executing
or
ScriptManager1.RegisterDataItem(Label2, "My extra data to pass", false);
// this is executing
}
But still getting Nothing in the args.get_dataItems();: // on the client
side
var dataItems = args.get_dataItems();
alert(dataItems['Label2']); ***** In here I get Undefined, I am hoping
to get "My extra data to pass"
also tried alert(dataItems[0]); and I get undefined.
What Am I missing, do you see any problems or tricks, Am I missing
something in config file??
Thank you,
Lit
"Braulio Diez" wrote in message
news:DBA29477-F33D-4251-9470-B96968EBA03D@microsoft.com...
> Hello,
>
> Take a look at InitializeRequest and EndRequest (on end request you can
> check which update panel triggered the petition and then run your
> javascript):
>
> http://asp.net/ajax/documentation/live/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerInitializeRequestEvent.aspx
>
> A sample code (this one is used to show and hid progress indicators when
> they are associated to a panel ID, ** bug on AJAX**):
>
> <script type="text/javascript">
> // Well... UpdateProgress only works fine with triggers if it's not
> associated to a single update panel
> // to make it work with a single panel (like the case we have in this
> case), we need to make a hack
> // intercept the call, check the control name (response.write needed
> from server because of the nasty
> // ctl_00 prefix added to the control), and then show the progress
> indicator associated to that control
> // very ugly stuff, but we only will need it if we have two update
> panles and two progress indicators.
> // http://geeks.ms/blogs/sergiotarrillo/archive/2007/05/06/14266.aspx
> var prm = Sys.WebForms.PageRequestManager.getInstance();
> prm.add_initializeRequest(InitializeRequest);
> prm.add_endRequest(EndRequest);
> var postBackElement;
>
> function InitializeRequest(sender, args) {
> if (prm.get_isInAsyncPostBack())
> {
> args.set_cancel(true);
> }
> postBackElement = args.get_postBackElement();
> // Dotnet panel
> if (postBackElement.id ==
> '<%Response.Write(btdotnetSearchFilter.ClientID.ToString());%>')
> {
>
> $get('<%Response.Write(UpdateProgressNet.ClientID.ToString());%>').style.display
> = "block";
> }
>
> // SQL Server Panel
> if (postBackElement.id ==
> '<%Response.Write(btnSQLServerfilter.ClientID.ToString());%>')
> {
>
> $get('<%Response.Write(UpdateProgressSQL.ClientID.ToString());%>').style.display
> = "block";
> }
>
> }
> function EndRequest (sender, args) {
> if (postBackElement.id ==
> '<%Response.Write(btnSQLServerfilter.ClientID.ToString());%>')
> {
>
> $get('<%Response.Write(UpdateProgressSQL.ClientID.ToString());%>').style.display
> = "none";
> }
> }
> function AbortPostBack() {
> if (prm.get_isInAsyncPostBack()) {
> prm.abortPostBack();
> }
> }
> </script>
>
>
> Good luck
> Braulio
>
> /// ------------------------------
> /// Braulio Diez
> ///
> /// http://www.tipsdotnet.com
> /// ------------------------------
>
>
>
>
> "Lit" wrote:
>
>> Hi,
>>
>> I would like to run some dynamic-JavaScript code at the end of a callback
>> of
>> an AJAX Call. for an update Panel
>>
>> 1---I click on a button on the browser,
>> 2---AJAX method called server
>> 3---some AJAX method get data from server , browser renders new info +
>> send
>> some JavaScript code with it.
>> 4---Then after that I would like to run a client side JavaScript code
>> that
>> came with the AJAX callback data.
>>
>> I tried to Register a Startup JavaScript code but it does not run within
>> AJAX ??
>>
>> Any Ideas??
>>
>> Thank You,
>>
>> Lit
>>
>>
>>
>>
>>
>>
>>
>>
>>
Date:Wed, 22 Aug 2007 12:15:52 -0700
Author:
|
Re: Hook to AJAX End Event on Client Side
My mistake, I was not using the Client Id of Label2
Although why dataItems[0] does not work???
Lit
"Lit" wrote in message
news:OzvYcDP5HHA.1208@TK2MSFTNGP03.phx.gbl...
> Hi Braulio,
>
> I am able to hook the EndRequestHandler and it is being Fired but I am
> unable to pass any args to it.
> I tried to use something like this
>
>
> if (ScriptManager1.IsInAsyncPostBack) // in code behind.
> {
>
> ScriptManager1.RegisterDataItem(Label2, "My extra data to pass"); // this
> is executing
> or
>
> ScriptManager1.RegisterDataItem(Label2, "My extra data to pass", false);
> // this is executing
> }
>
> But still getting Nothing in the args.get_dataItems();: // on the
> client side
>
> var dataItems = args.get_dataItems();
> alert(dataItems['Label2']); ***** In here I get Undefined, I am
> hoping to get "My extra data to pass"
>
> also tried alert(dataItems[0]); and I get undefined.
>
> What Am I missing, do you see any problems or tricks, Am I missing
> something in config file??
>
> Thank you,
>
> Lit
>
>
> "Braulio Diez" wrote in message
> news:DBA29477-F33D-4251-9470-B96968EBA03D@microsoft.com...
>> Hello,
>>
>> Take a look at InitializeRequest and EndRequest (on end request you can
>> check which update panel triggered the petition and then run your
>> javascript):
>>
>> http://asp.net/ajax/documentation/live/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerInitializeRequestEvent.aspx
>>
>> A sample code (this one is used to show and hid progress indicators when
>> they are associated to a panel ID, ** bug on AJAX**):
>>
>> <script type="text/javascript">
>> // Well... UpdateProgress only works fine with triggers if it's not
>> associated to a single update panel
>> // to make it work with a single panel (like the case we have in this
>> case), we need to make a hack
>> // intercept the call, check the control name (response.write needed
>> from server because of the nasty
>> // ctl_00 prefix added to the control), and then show the progress
>> indicator associated to that control
>> // very ugly stuff, but we only will need it if we have two update
>> panles and two progress indicators.
>> // http://geeks.ms/blogs/sergiotarrillo/archive/2007/05/06/14266.aspx
>> var prm = Sys.WebForms.PageRequestManager.getInstance();
>> prm.add_initializeRequest(InitializeRequest);
>> prm.add_endRequest(EndRequest);
>> var postBackElement;
>>
>> function InitializeRequest(sender, args) {
>> if (prm.get_isInAsyncPostBack())
>> {
>> args.set_cancel(true);
>> }
>> postBackElement = args.get_postBackElement();
>> // Dotnet panel
>> if (postBackElement.id ==
>> '<%Response.Write(btdotnetSearchFilter.ClientID.ToString());%>')
>> {
>>
>> $get('<%Response.Write(UpdateProgressNet.ClientID.ToString());%>').style.display
>> = "block";
>> }
>>
>> // SQL Server Panel
>> if (postBackElement.id ==
>> '<%Response.Write(btnSQLServerfilter.ClientID.ToString());%>')
>> {
>>
>> $get('<%Response.Write(UpdateProgressSQL.ClientID.ToString());%>').style.display
>> = "block";
>> }
>>
>> }
>> function EndRequest (sender, args) {
>> if (postBackElement.id ==
>> '<%Response.Write(btnSQLServerfilter.ClientID.ToString());%>')
>> {
>>
>> $get('<%Response.Write(UpdateProgressSQL.ClientID.ToString());%>').style.display
>> = "none";
>> }
>> }
>> function AbortPostBack() {
>> if (prm.get_isInAsyncPostBack()) {
>> prm.abortPostBack();
>> }
>> }
>> </script>
>>
>>
>> Good luck
>> Braulio
>>
>> /// ------------------------------
>> /// Braulio Diez
>> ///
>> /// http://www.tipsdotnet.com
>> /// ------------------------------
>>
>>
>>
>>
>> "Lit" wrote:
>>
>>> Hi,
>>>
>>> I would like to run some dynamic-JavaScript code at the end of a
>>> callback of
>>> an AJAX Call. for an update Panel
>>>
>>> 1---I click on a button on the browser,
>>> 2---AJAX method called server
>>> 3---some AJAX method get data from server , browser renders new info +
>>> send
>>> some JavaScript code with it.
>>> 4---Then after that I would like to run a client side JavaScript code
>>> that
>>> came with the AJAX callback data.
>>>
>>> I tried to Register a Startup JavaScript code but it does not run within
>>> AJAX ??
>>>
>>> Any Ideas??
>>>
>>> Thank You,
>>>
>>> Lit
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>
>
Date:Wed, 22 Aug 2007 12:33:17 -0700
Author:
|
Re: Hook to AJAX End Event on Client Side
Using args, I can get without problems which control was the on who triggered
the out of bound call, something like
postBackElement = args.get_postBackElement();
// Dotnet panel
if (postBackElement.id ==
'<%Response.Write(btdotnetSearchFilter.ClientID.ToString());%>')
About using DataItems, take a look at this link:
http://jeffzon.net/Blog/post/Something-you-probably-missed-about-registering-data-items.aspx
HTH
Braulio
/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------
"Lit" wrote:
> Hi Braulio,
>
> I am able to hook the EndRequestHandler and it is being Fired but I am
> unable to pass any args to it.
> I tried to use something like this
>
>
> if (ScriptManager1.IsInAsyncPostBack) // in code behind.
> {
>
> ScriptManager1.RegisterDataItem(Label2, "My extra data to pass"); // this
> is executing
> or
>
> ScriptManager1.RegisterDataItem(Label2, "My extra data to pass", false);
> // this is executing
> }
>
> But still getting Nothing in the args.get_dataItems();: // on the client
> side
>
> var dataItems = args.get_dataItems();
> alert(dataItems['Label2']); ***** In here I get Undefined, I am hoping
> to get "My extra data to pass"
>
> also tried alert(dataItems[0]); and I get undefined.
>
> What Am I missing, do you see any problems or tricks, Am I missing
> something in config file??
>
> Thank you,
>
> Lit
>
>
> "Braulio Diez" wrote in message
> news:DBA29477-F33D-4251-9470-B96968EBA03D@microsoft.com...
> > Hello,
> >
> > Take a look at InitializeRequest and EndRequest (on end request you can
> > check which update panel triggered the petition and then run your
> > javascript):
> >
> > http://asp.net/ajax/documentation/live/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerInitializeRequestEvent.aspx
> >
> > A sample code (this one is used to show and hid progress indicators when
> > they are associated to a panel ID, ** bug on AJAX**):
> >
> > <script type="text/javascript">
> > // Well... UpdateProgress only works fine with triggers if it's not
> > associated to a single update panel
> > // to make it work with a single panel (like the case we have in this
> > case), we need to make a hack
> > // intercept the call, check the control name (response.write needed
> > from server because of the nasty
> > // ctl_00 prefix added to the control), and then show the progress
> > indicator associated to that control
> > // very ugly stuff, but we only will need it if we have two update
> > panles and two progress indicators.
> > // http://geeks.ms/blogs/sergiotarrillo/archive/2007/05/06/14266.aspx
> > var prm = Sys.WebForms.PageRequestManager.getInstance();
> > prm.add_initializeRequest(InitializeRequest);
> > prm.add_endRequest(EndRequest);
> > var postBackElement;
> >
> > function InitializeRequest(sender, args) {
> > if (prm.get_isInAsyncPostBack())
> > {
> > args.set_cancel(true);
> > }
> > postBackElement = args.get_postBackElement();
> > // Dotnet panel
> > if (postBackElement.id ==
> > '<%Response.Write(btdotnetSearchFilter.ClientID.ToString());%>')
> > {
> >
> > $get('<%Response.Write(UpdateProgressNet.ClientID.ToString());%>').style.display
> > = "block";
> > }
> >
> > // SQL Server Panel
> > if (postBackElement.id ==
> > '<%Response.Write(btnSQLServerfilter.ClientID.ToString());%>')
> > {
> >
> > $get('<%Response.Write(UpdateProgressSQL.ClientID.ToString());%>').style.display
> > = "block";
> > }
> >
> > }
> > function EndRequest (sender, args) {
> > if (postBackElement.id ==
> > '<%Response.Write(btnSQLServerfilter.ClientID.ToString());%>')
> > {
> >
> > $get('<%Response.Write(UpdateProgressSQL.ClientID.ToString());%>').style.display
> > = "none";
> > }
> > }
> > function AbortPostBack() {
> > if (prm.get_isInAsyncPostBack()) {
> > prm.abortPostBack();
> > }
> > }
> > </script>
> >
> >
> > Good luck
> > Braulio
> >
> > /// ------------------------------
> > /// Braulio Diez
> > ///
> > /// http://www.tipsdotnet.com
> > /// ------------------------------
> >
> >
> >
> >
> > "Lit" wrote:
> >
> >> Hi,
> >>
> >> I would like to run some dynamic-JavaScript code at the end of a callback
> >> of
> >> an AJAX Call. for an update Panel
> >>
> >> 1---I click on a button on the browser,
> >> 2---AJAX method called server
> >> 3---some AJAX method get data from server , browser renders new info +
> >> send
> >> some JavaScript code with it.
> >> 4---Then after that I would like to run a client side JavaScript code
> >> that
> >> came with the AJAX callback data.
> >>
> >> I tried to Register a Startup JavaScript code but it does not run within
> >> AJAX ??
> >>
> >> Any Ideas??
> >>
> >> Thank You,
> >>
> >> Lit
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
>
>
>
Date:Thu, 23 Aug 2007 01:42:04 -0700
Author:
|
|
|