Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to call javascript function in page_load event without any control attachment

How to call javascript function in page_load event without any control attachment

Scheduled Pinned Locked Moved ASP.NET
javascripttutorial
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xodeblack
    wrote on last edited by
    #1

    How to call javascript function in page_load event without any control attachment

    Dre@m is not th@t wh@t u see in sleep.Dre@m is the thing which does not allow u to sleep

    N A B P C 5 Replies Last reply
    0
    • X xodeblack

      How to call javascript function in page_load event without any control attachment

      Dre@m is not th@t wh@t u see in sleep.Dre@m is the thing which does not allow u to sleep

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Read about ClientScriptManager.RegisterStartupScript[^] method.

      Best wishes, Navaneeth

      1 Reply Last reply
      0
      • X xodeblack

        How to call javascript function in page_load event without any control attachment

        Dre@m is not th@t wh@t u see in sleep.Dre@m is the thing which does not allow u to sleep

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        Try This one, Use this code in your Code Behind

        Page.ClientScript.RegisterStartupScriptthis.GetType(), "JSFunc", "MyFunc();", true);

        This is your JavaScript Code :

        function MyFunc()
        {

               alert('JS Calling From Code Behind');
            }
        

        Hope this will help you :D

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

        X 1 Reply Last reply
        0
        • A Abhijit Jana

          Try This one, Use this code in your Code Behind

          Page.ClientScript.RegisterStartupScriptthis.GetType(), "JSFunc", "MyFunc();", true);

          This is your JavaScript Code :

          function MyFunc()
          {

                 alert('JS Calling From Code Behind');
              }
          

          Hope this will help you :D

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

          X Offline
          X Offline
          xodeblack
          wrote on last edited by
          #4

          thankz Abhijit Jana

          Dre@m is not th@t wh@t u see in sleep.Dre@m is the thing which does not allow u to sleep

          1 Reply Last reply
          0
          • X xodeblack

            How to call javascript function in page_load event without any control attachment

            Dre@m is not th@t wh@t u see in sleep.Dre@m is the thing which does not allow u to sleep

            B Offline
            B Offline
            Brij
            wrote on last edited by
            #5

            Page.ClientScript

            wont work in case if you are using AJAX in your page.At that time use Scriptmanager to register the clientscrit as ScriptManager.RegisterStartupScript(this.Page, this.GetType(), this.ClientID, "MyFunc();", true); Rest will same as Abhijit said.

            Cheers!! Brij

            1 Reply Last reply
            0
            • X xodeblack

              How to call javascript function in page_load event without any control attachment

              Dre@m is not th@t wh@t u see in sleep.Dre@m is the thing which does not allow u to sleep

              P Offline
              P Offline
              Pranay Rana
              wrote on last edited by
              #6

              you can also achive same thing by using jquery. and for more detail check jquery documentation on jquery site <script type="text/javascript" src="JavaScript/jquery.js"> </script> <script type="text/javascript"> $(document).ready(function(){ alert('page loaded'); });

              1 Reply Last reply
              0
              • X xodeblack

                How to call javascript function in page_load event without any control attachment

                Dre@m is not th@t wh@t u see in sleep.Dre@m is the thing which does not allow u to sleep

                C Offline
                C Offline
                carlecomm
                wrote on last edited by
                #7

                Hi, method1. code behind: this.Page.RegisterStartupScript(string key, string script); method2. put your javascript function content(just the content) in the *.aspx body or div.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups