This is a migrated thread and some comments may be shown as answers.

Registering javascript on code-behind

4 Answers 668 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Venkatesh
Top achievements
Rank 1
Venkatesh asked on 10 Sep 2007, 01:30 PM
Hi,

i would like to know how to run registered script through an auto postback event of the control which is residing in radajaxpanel.

Sample code given below but when i execute the below code nothing happens but i want to open window through javascript reply me ASAP.

Thanks in advance...........

protected void btn_Click(object sender, EventArgs e)
    {
    

        //Java script to open the window for Billboard preview
        if (ClientScript != null)
            if (!ClientScript.IsStartupScriptRegistered("Startup"))
            {
                string scriptString;
                scriptString = "<script language=javascript>";
                scriptString = string.Format("{0} window.open('page1.aspx?ID=' + document.frm1.hidID.value, '_blank', 'width=300, height=430, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no', 'true');", scriptString);
                scriptString = scriptString + "</script>";
                RegisterStartupScript("Startup", scriptString);              
                
            }
    }


Regds,

Boogie.

4 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 10 Sep 2007, 02:50 PM
Hello Venkatesh,

You need to use the static methods of the ScriptManager to register client-side scripts. More info is available here.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
abhishek
Top achievements
Rank 1
answered on 30 Jul 2008, 06:26 AM
Hi vankatesh

I think u r missing at   RegisterStartupScript("Startup", scriptString);              

Use it
Page.RegisterStartupScript("Startup", scriptString);    

And if it is in Update panel ,Then 
ScriptManager.  RegisterStartupScript("Startup", scriptString);           like this.


Hope that this will help you.

Abhishek udiya
Diaspark Inc,Indore.
    



          
0
abhishek
Top achievements
Rank 1
answered on 16 Feb 2009, 12:44 PM

Please overload right method as follow:

protected void btn_Click(object sender, EventArgs e)
    {
     
        ScriptManager.RegisterClientScriptBlock(this, GetType(), "alert", "test();", true);
          
          // --- (OR) Simple call alert.

 

            ScriptManager

 

.RegisterClientScriptBlock(this, GetType(), "alert", String.Format("alert('Hello');"), true);

 

 

 

 

   }
Here test() is ur javascript function.and btn control is in UpdatePanel.


Abhishek Udiya
0
Tejas
Top achievements
Rank 1
answered on 03 Apr 2009, 06:59 AM
You can find the simplest method to Register javascript on codebehind here:

http://dotnetjavascriptsolutions.blogspot.com/2009/04/simple-way-to-register-javascript.html



Tags
Ajax
Asked by
Venkatesh
Top achievements
Rank 1
Answers by
Steve
Telerik team
abhishek
Top achievements
Rank 1
Tejas
Top achievements
Rank 1
Share this question
or