Dotnetplace.com

.NET Articles, Web Devploment, ASP.NET, HTML, Sharepoint 2010, Aamir Hasan
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here

Advertise

Loading...


Posted by Mairaj   on Sunday, June 10, 2012 Total Views:  

Sometimes you want to call javascript finctions from code behind.In this case you would use ClientScriptManager to do this.Let’s see an example.Here we would call a javascript function which shows an alert.Create a function in javascript ShowAlert().On Page_Load we will call this function.

Desgin code

<html>

<head runat="server">

    <title></title>

    <script type="text/javascript">

        function ShowAlert() {

            alert('This is being called from code behind');

        }

    </script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    </div>

    </form>

    <p><a href="http://www.dotnetplace.com">ASP.NET controls with jquery</a></p>

</body>

</html>

 

Code behind

Now we will call the above javscript method from server side by using RegisterStartupScript

 

   protected void Page_Load(object sender, EventArgs e)

    {

        ClientScriptManager cs = Page.ClientScript;

        cs.RegisterStartupScript(this.GetType(), "script", "ShowAlert();", true);

    }

 

Here you would have noted that the RegisterStartupScript method of ClientScriptManager class accepts four parameters.

  1. Control that registers the Script. Here page is registerig the script.
  2. This could be any key you want to write but make sure another script is not registered with this key.
  3. The script to be executed.Here you can write name of method to be executed or you can write script directly.
  4. Script tags to be added.true for yes false for not.


Microsoft Reference

ClientScriptManager.RegisterStartupScript Method


Ouput

Download

Call-javascript-function-from-server.zip (980.00 bytes)

Demo

See live demo

Protected by Copyscape Online Plagiarism Tool

Comments (10) -

besi beton
besi beton United States
8/3/2015 11:43:18 PM #

sangat disukai kontraktor cek langsung bos untuk proyek bangunan murah meriah banget

besi beton
besi beton United States
8/4/2015 12:06:16 AM #

super hemat mari buktikan Kami Jamin Yang Terbagus Kami Berikan Yang Terbaik <a href="besibetonpabrik.blogspot.com/.../mana-ada-yang-seperti-perusahaan-ini.html">Harga Besi Beton</a>

besi beton
besi beton United States
8/4/2015 1:30:38 AM #

Membuat Hati seneng konstruksi hemat Tak Usah Cari Lagi mari buktikan <a href="sangkarsangkarbesibaja.wordpress.com/.../">Harga Besi Beton</a>

besi beton
besi beton United States
8/4/2015 9:33:08 AM #

Kami Siap Diomelin jika mahal pasti cocok bos hanya disini yang sudah teruji ukuran paling bagus <a href="komposerreaksi.wordpress.com/.../">Harga Besi Beton</a>

harga besi beton
harga besi beton United States
8/4/2015 6:17:38 PM #

bikin Perusahaan Untung Banyak siap memanjakan anda Ini Membantai Harga Pasaran kami Akan Membuat Anda Untung Banyak <a href="sangkarsangkarbesibaja.wordpress.com/.../">Harga Besi Beton</a>

besi beton
besi beton United States
8/4/2015 10:31:40 PM #

Tidak Repot Proses Mudah ukuran bervariasi Dapatkan Kesempatan Terbatas Disini Mari Cek Sama - Sama <a href="komposerreaksi.wordpress.com/.../">Harga Besi Beton</a>

blog baja 33662
blog baja 33662 United States
8/5/2015 7:33:47 AM #

special offers ironsteelcenter wrote as expected builders Try Just check dimari <a href="jualbesihbeam.blogspot.com/.../harga-besi-h-beam-murah-banget-cari-hal.html">Harga H beam</a>

blog besi 93615
blog besi 93615 United States
8/5/2015 8:53:16 AM #

gak akan Kecewa cek disini kami juaranya paling terdepan asli barangnya <a href="besibetonpabrik.blogspot.com/.../anda-dapatkan-semua-disini-harga-pipa.html">Harga Pipa Schedule 80</a>

blog baja 57558
blog baja 57558 United States
8/5/2015 11:05:06 AM #

silahkan coba Kami Melayani Anda Sepenuh Hati kami menjamin Kepuasan Anda tunggu apa lagi? kontak ! <a href="komposerreaksi.wordpress.com/.../">Harga stainless steel</a>

blog baja 27558
blog baja 27558 United States
8/5/2015 2:03:40 PM #

dijamin pelayanan kami memuaskan Mantap Dan Bukti Nyata kami memberi keuntungan banyak Daripada Di Tempat Lain <a href="pabrikbesisiku.blogspot.com/.../komplit-disini-bos-harga-baja-ringan.html">Harga Baja Ringan</a>

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5