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. running java script on page loading

running java script on page loading

Scheduled Pinned Locked Moved ASP.NET
javatools
10 Posts 4 Posters 11 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.
  • 2 Offline
    2 Offline
    2489128
    wrote on last edited by
    #1

    hi!, there is a page, say, my.aspx. in this there is a .... block contains a function say func(). i want whenever my.aspx page loaded this function func() get executed on every post back.

    _ 1 Reply Last reply
    0
    • 2 2489128

      hi!, there is a page, say, my.aspx. in this there is a .... block contains a function say func(). i want whenever my.aspx page loaded this function func() get executed on every post back.

      _ Offline
      _ Offline
      _AK_
      wrote on last edited by
      #2

      You can call that javascript function on onload event of the body tag in the html section.

      Best Regards, Apurva Kaushal

      2 1 Reply Last reply
      0
      • _ _AK_

        You can call that javascript function on onload event of the body tag in the html section.

        Best Regards, Apurva Kaushal

        2 Offline
        2 Offline
        2489128
        wrote on last edited by
        #3

        Thanks! but i have to passed some values from code behind from to that java script function.

        P _ G 3 Replies Last reply
        0
        • 2 2489128

          Thanks! but i have to passed some values from code behind from to that java script function.

          P Offline
          P Offline
          psamy
          wrote on last edited by
          #4

          Hi, u can use the following server side function. if (!(this.IsStartupScriptRegistered("Startup"))) Page.RegisterStartupScript("StartUp","fun('"+ arg1 + "')");

          1 Reply Last reply
          0
          • 2 2489128

            Thanks! but i have to passed some values from code behind from to that java script function.

            _ Offline
            _ Offline
            _AK_
            wrote on last edited by
            #5

            exactly same way you can do as psamy said. also you can even write complete function in code behind itself.

            Best Regards, Apurva Kaushal

            2 1 Reply Last reply
            0
            • _ _AK_

              exactly same way you can do as psamy said. also you can even write complete function in code behind itself.

              Best Regards, Apurva Kaushal

              2 Offline
              2 Offline
              2489128
              wrote on last edited by
              #6

              Give some example

              _ 1 Reply Last reply
              0
              • 2 2489128

                Give some example

                _ Offline
                _ Offline
                _AK_
                wrote on last edited by
                #7

                something like this you can use..: string str = ""; str += "function Focu(){"; str += "document.getElementById('TextBox3').focus();}<"; str += "/"; str += "script>"; if(!IsStartupScriptRegistered("Test")) { Page.RegisterStartupScript("Test",str); }</code> <div class="ForumSig">Best Regards, Apurva Kaushal</div></x-turndown>

                2 1 Reply Last reply
                0
                • _ _AK_

                  something like this you can use..: string str = ""; str += "function Focu(){"; str += "document.getElementById('TextBox3').focus();}<"; str += "/"; str += "script>"; if(!IsStartupScriptRegistered("Test")) { Page.RegisterStartupScript("Test",str); }</code> <div class="ForumSig">Best Regards, Apurva Kaushal</div></x-turndown>

                  2 Offline
                  2 Offline
                  2489128
                  wrote on last edited by
                  #8

                  Thanks! It Working Correctly.

                  _ 1 Reply Last reply
                  0
                  • 2 2489128

                    Thanks! It Working Correctly.

                    _ Offline
                    _ Offline
                    _AK_
                    wrote on last edited by
                    #9

                    always welcome... :)

                    Best Regards, Apurva Kaushal

                    1 Reply Last reply
                    0
                    • 2 2489128

                      Thanks! but i have to passed some values from code behind from to that java script function.

                      G Offline
                      G Offline
                      Guffa
                      wrote on last edited by
                      #10

                      There are several ways. You could insert a value in the function: var x = <asp:Literal id="objValue" runat="server" />; and in the codebehind insert the value: objValue.Text = "42"; You could make the body tag accessible from codebehind: <body id="Body" runat="server"> and set the onload event from codebehind: Body.Attributes["onload"] = "somefunc(42);"; You could add the code in a script tag: this.ClientScript.RegisterStartupScript(this.GetType(), "init", "somefunc(42);", true); Note that if you use RegisterStartupScript the code will run while the page is loading, not when it has finished loading, as it does when you use the onload event.

                      --- b { font-weight: normal; }

                      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