6 Answers, 1 is accepted

You can try the following approaches to execute javascript after a button click.
1. C#:
protected
void
btn_Click(
object
sender, EventArgs e)
{
string
radconfirmscript =
"<script language='javascript'>function f(){test(); Sys.Application.remove_load(f) ;}; Sys.Application.add_load (f);</script>"
;
Page.ClientScript.RegisterStartupScript(
this
.GetType(),
"radconfirm"
, radconfirmscript);
}
JS:
<script type=
"text/javascript"
>
function
test()
{
alert(
"Hi"
);
}
</script>
2. C#:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
Response.Write(
"<script language=JavaScript> alert('Hello'); </script>"
);
}
3. C#:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
string
s =
"<script language=JavaScript>alert('Hello');</script>"
;
Page.ClientScript.RegisterStartupScript(
this
.GetType(),
"test"
, s);
}
Thanks,
Shinu.

I am surprised that telerik is not planned an afterpostback feature for the controls!!!!
Anthem, free library, had planned everything!
Thank you and have a good day
Anne
I would also recommend using the RegisterStartupScript method of the ScriptManager control in order to register a client script that will be executed after the postback. This method can be used as shown below:
Page Markup:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
asp:ScriptManager
ID
=
"Scriptmanager1"
runat
=
"server"
/>
<
div
>
<
telerik:RadButton
runat
=
"server"
ID
=
"RadButton"
Text
=
"Click"
onclick
=
"RadButton_Click"
></
telerik:RadButton
>
</
div
>
</
form
>
</
body
>
</
html
>
Code-Behind:
protected
void
RadButton_Click(
object
sender, EventArgs e)
{
string
script =
"alert('Hello');"
;
ScriptManager.RegisterStartupScript(
this
,
this
.GetType(),
"testScript"
, script,
true
);
}
The afterpostback feature that you are suggesting is indeed interesting. It will be brought to the attention of our developers and it will be considered for implementation, depending on its popularity. I have logged this request as a PITS Issue. You can check its status by following this link: Public URL.
Feel free to contact us again if you encounter more difficulties.
All the best,
Slav
the Telerik team

Very good day, rainy in France
Anne

I've been struggling with this for a few days now and can't seem to get it to work. I'm guessing my problem might be that I've got a more complicated situation with 2 master pages and a couple ascx pages? .ascx page #1 has a folder tree on right and loads .ascx page #2 based on what folder is clicked.
Here's my issues:
1. If I put the script in the .ascx page it doesn't get added to the page. I have to put it in the .aspx page that calls the 2 ascx controls.
2. It will show up in my debugging but it never gets hit?
Here's what I'm using code wise (asp.net)
JS call inside of a Telerik:RadCodeBlock
function viewFolderDocuments() {
var strUrl;
strUrl = '<%=GetViewStateString(PDMPlanroom.QUERY_STR_VIEW_URL)%>';
window.open(strUrl, "_blank");
Then my codebehind button click event has this code:
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "viewFolderDocuments", "viewFolderDocuments();", True)
The script NEVER gets hit?

If it can help you
1
/ We are also working with a treeview on a main page PP
Our page is divided into
two radpane by a splitter
Click on treeview
(client side) , we modified the right radPane adress
function onClientNodeClick(sender, args) {
var treeNode = args.get_node();
treeNode.set_selected(true);
var ZoneDetail = $find("<%=PaneDetail.ClientID%>");
var Categorie = treeNode._attributes.getAttribute("Categorie");
var ID = treeNode.get_value();
NoeudEnCours
= treeNode;
switch (Categorie) {
case"F-Personnes":
{
ZoneDetail.set_contentUrl(repPersonnes
+ "Personne.aspx?Action=M&PerID=" + ID);
FicheEnCours.Action
= "M";
}
break;
case"F-Forets":
{
ZoneDetail.set_contentUrl(repForets
+ "Foret.aspx?Action=M&ForID=" + ID);
}
break;
......
2
/ To update the treeview from the detail page PD ....
Server side
PrivateSub MajTreeviewPrinc(CPCommune AsString)
Dim Libelle AsString
…...
Try
Fnscript
= "<script>Maj('" & Libelle & "')</script>"
ScriptManager.RegisterStartupScript(Page, Me.GetType(), "Maj",
Fnscript, False)
EndIf
Catch Ex AsException
EndTry
EndSub
Client Side
function Maj(LibelleNom) {
var tv = window.parent;
tv.MajLibelle(LibelleNom);
}
And on PP
Client Side
function MajLibelle(libelle) {
treeView
= $find("<%= tvPersonnes.ClientID %>");
var node = treeView.get_selectedNodes();
node[0].set_text(libelle);
}
Have a good day
Anne