Wednesday, March 28, 2012

Calling jvascript function from the button under UpdatePanel

Hello,

I am having a a web application developed using asp.net2.0 with vb.net as a language.

In this web application i am having two buttons and one update panel. Now my button1 is outside the updatepanel and another button2 is present inside the updatepanel.

In asp.net if we want to run any javascript function on the click of a button then we normally use the button.attribute.add() function but if we want that when user click on button then first some server side code will be performed and then the javascript function will be called.

For that we uses the below code in asp.net !!!

Page.ClientScript.RegisterClientScriptBlock(Me.GetType,"Script", "<Script>alert('Hello');</Script>")

this code is working fine on the click event of the button that is present outside the update panel. But when i am running the same code on the click event of the button that is present inside the updatepanel then its not working,

Remeber that i d't want to run the javascript code when user just click on the button , i want first some server side code wil perform his work then after this script will run.

But for controls under update panel its not working.??

please paste your code here, because I am doing almost the same thing here without any issues.


Hi,

Add a Literal control to your web form.

In your Click method use this code:

literal1.Text = "<script type=\"text/javascript\"> alert('Hello world!');</script>";

Dont forget to clear Text property in another postbacks.


Use ScriptManager.RegisterStartupScript, instead of the ClientScript class' method.


Can anyone tell me the solution for this?

Me too getting the same issue.

Thanks,

Jasmeeta.