Monday, March 26, 2012

Call javascript function after UpdatePanel

Greetings, I have an UpdatePanel that gets triggered by a ControlEventTrigger button
click event. My question is this:
After the Update (request) is complete, I need to run a javascript function to do some work.
Is there a sort of "OnRequestComplete" property that I can use to specify the names of the JS functions that i want to run?


Thanks.

There isn't anything like OnRequestComplete that you can use. However, this is possible. In whatever server-side code that is executed.

ClientScript.RegisterStartupScript(Me.GetType(),"alert('Update done.');",true)

rchern13, the example you gave me above works fine.
ClientScript.RegisterStartupScript(Me.GetType(), "KeyName", "alert('Update done.');" ,true)

but if I put the alert inside a function, the function doesn't run.
ClientScript.RegisterStartupScript(Me.GetType(), "KeyName", "function update() {alert('Update done.');}" ,true)

Any thoughts? Thanks.


Where do you call the update function?

Hey guys please note ..

If you want the script to be registered at runtime you must make sure that the page does postback andthis should not be an atlas post back because in such case the script will not register or fire the required command

It should be done in PageLoad Event of the Asp.Net Page

or if you are not using Atlas in you application to display messages you can use the following code

Sub AlertMessage(ByVal StrMessage As String)
Dim strScript As String = "<script language=JavaScript>"
strScript += "alert(""" & StrMessage & """);"
strScript += "</script>"

If (Not Page.ClientScript.IsStartupScriptRegistered("Alertscript")) Then

'For asp.Net 1.0 and +
'Page.ClientScript.RegisterStartupScript("clientScript", strScript)

'For asp.Net 2.0
Page.ClientScript.RegisterStartupScript(Me.GetType, "Alertscript", strScript)
End If
End Sub


Asifsolkar, I disagree with you. I have a page with a structure like the following:

Page
--Update Panel
--Details View
--Command Button

The command button event handler includes the following line:

ClientScript.RegisterStartupScript(

Me.GetType,"approve","alert('" & str &"'); ",True)

The final effect of this is that my page inserts the record (the DV is in insert mode by default) into the database and I see the alert without a full postback.


I agree with rchern13. I was registering the function, but not calling it. Once I made a call to my JS functions, things are running as intended.
Rchern13, This forum is lucky to have an expert like you! Your time and help are appreciated.

Thanks.


Big Smile

I'm no expert, just somehow who drove everyone crazy while I was learning Atlas and am now trying to do my part to help the community.


Hi, I need to do that same - but couldnt get it to work withv2.0.50727.60626, does this work with this version? Or is thisthere any alternative?

Thanks
Jim
Yes, it will work. What error are you getting?
Thanks for replying, I wasn't actually getting any error, it's just wasn't firing the alert.

However, I just tried removing the other custom controls from my form(which emit their own JS) and it works... so I guess theres someconflict there.

Thanks
Jim

No comments:

Post a Comment