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. General Programming
  3. C#
  4. JavaScript in ASP.NET

JavaScript in ASP.NET

Scheduled Pinned Locked Moved C#
csharpjavascriptasp-nettutorial
7 Posts 2 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.
  • J Offline
    J Offline
    Jabeerbe
    wrote on last edited by
    #1

    How to use the Javascript function in asp.net. THis is my sample code. <%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default.aspx.cs" Inherits="_Default" %> function displayMessage() { alert("Hello world!"); } Untitled Page

    Regards, A Jabeer Ali

    K 1 Reply Last reply
    0
    • J Jabeerbe

      How to use the Javascript function in asp.net. THis is my sample code. <%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default.aspx.cs" Inherits="_Default" %> function displayMessage() { alert("Hello world!"); } Untitled Page

      Regards, A Jabeer Ali

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      The OnClick method of your button needs to point to a method in your codebehind file. If you are using asp.net 2.0 you can set a onClientClick to your javascript method. If you are using asp.net 1.1 or 1.0 you need some code in the page load that takes the button control and does and Attribute.Add("OnClick","displayMessage"); Hope that helps. Ben

      J 1 Reply Last reply
      0
      • K kubben

        The OnClick method of your button needs to point to a method in your codebehind file. If you are using asp.net 2.0 you can set a onClientClick to your javascript method. If you are using asp.net 1.1 or 1.0 you need some code in the page load that takes the button control and does and Attribute.Add("OnClick","displayMessage"); Hope that helps. Ben

        J Offline
        J Offline
        Jabeerbe
        wrote on last edited by
        #3

        Thank u thats working fine. and do you have any solution for the onload event.

        Regards, A Jabeer Ali

        K 1 Reply Last reply
        0
        • J Jabeerbe

          Thank u thats working fine. and do you have any solution for the onload event.

          Regards, A Jabeer Ali

          K Offline
          K Offline
          kubben
          wrote on last edited by
          #4

          In the page load event If (!IsPostBack) { Button1.Attributes.Add("onClick","displayMessage"); } Ben

          J 1 Reply Last reply
          0
          • K kubben

            In the page load event If (!IsPostBack) { Button1.Attributes.Add("onClick","displayMessage"); } Ben

            J Offline
            J Offline
            Jabeerbe
            wrote on last edited by
            #5

            No No. I have done ur clientclick Event. Which is working fine. But i need the same type of event for the Page onload Event also. Would you help me.

            Regards, A Jabeer Ali

            K 1 Reply Last reply
            0
            • J Jabeerbe

              No No. I have done ur clientclick Event. Which is working fine. But i need the same type of event for the Page onload Event also. Would you help me.

              Regards, A Jabeer Ali

              K Offline
              K Offline
              kubben
              wrote on last edited by
              #6

              If you want some javascript to run when the page loads you will have to set the onload event in the body tag in your html. Hope that helps. Ben

              J 1 Reply Last reply
              0
              • K kubben

                If you want some javascript to run when the page loads you will have to set the onload event in the body tag in your html. Hope that helps. Ben

                J Offline
                J Offline
                Jabeerbe
                wrote on last edited by
                #7

                S mate. ur Rite But that javascript is not even Called by the onload event.

                Regards, A Jabeer Ali

                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