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. JavaScript
  4. How to call event using javascript?

How to call event using javascript?

Scheduled Pinned Locked Moved JavaScript
csharpjavascripthtmlcomsysadmin
4 Posts 3 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.
  • S Offline
    S Offline
    Sandesh M Patil
    wrote on last edited by
    #1

    My aspx page contains following code

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">

        function fnClickCalc() {
    
            document.getElementById('<%= btnCalc.ClientID  %>').click();
           
        }
    </script>
    

    </head>
    <body>
    <form id="form1" runat="server">

    </form>
    

    </body>
    </html>

    My code behind file is,

    protected void btnCalc_Click(object sender, EventArgs e)
    {

     lblResult.Text = lblFirstNo.Text + lblsecondNo.Text;
    

    }

    When i click "Button1" button it fires btnCalc_Click event but i am not getting "55" result since page load again fires after "btnCalc_Click" event. However if i click "btnCalc", it shows me desired output. Any suggestions.. :)

    Cheers,
    SMP

    My Recent Article
    Main Method in C#

    Richard DeemingR A 2 Replies Last reply
    0
    • S Sandesh M Patil

      My aspx page contains following code

      <html xmlns="http://www.w3.org/1999/xhtml">
      <head runat="server">
      <title></title>
      <script type="text/javascript" language="javascript">

          function fnClickCalc() {
      
              document.getElementById('<%= btnCalc.ClientID  %>').click();
             
          }
      </script>
      

      </head>
      <body>
      <form id="form1" runat="server">

      </form>
      

      </body>
      </html>

      My code behind file is,

      protected void btnCalc_Click(object sender, EventArgs e)
      {

       lblResult.Text = lblFirstNo.Text + lblsecondNo.Text;
      

      }

      When i click "Button1" button it fires btnCalc_Click event but i am not getting "55" result since page load again fires after "btnCalc_Click" event. However if i click "btnCalc", it shows me desired output. Any suggestions.. :)

      Cheers,
      SMP

      My Recent Article
      Main Method in C#

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Try:

      OnClientClick="fnClickCalc();return false;"


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      S 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Try:

        OnClientClick="fnClickCalc();return false;"


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        S Offline
        S Offline
        Sandesh M Patil
        wrote on last edited by
        #3

        Thanks..It works..It was so simple. Really appreciate your answer :-D

        Cheers,
        SMP

        My Recent Article
        Main Method in C#

        1 Reply Last reply
        0
        • S Sandesh M Patil

          My aspx page contains following code

          <html xmlns="http://www.w3.org/1999/xhtml">
          <head runat="server">
          <title></title>
          <script type="text/javascript" language="javascript">

              function fnClickCalc() {
          
                  document.getElementById('<%= btnCalc.ClientID  %>').click();
                 
              }
          </script>
          

          </head>
          <body>
          <form id="form1" runat="server">

          </form>
          

          </body>
          </html>

          My code behind file is,

          protected void btnCalc_Click(object sender, EventArgs e)
          {

           lblResult.Text = lblFirstNo.Text + lblsecondNo.Text;
          

          }

          When i click "Button1" button it fires btnCalc_Click event but i am not getting "55" result since page load again fires after "btnCalc_Click" event. However if i click "btnCalc", it shows me desired output. Any suggestions.. :)

          Cheers,
          SMP

          My Recent Article
          Main Method in C#

          A Offline
          A Offline
          Akii Malam
          wrote on last edited by
          #4

          Include jquery library from Jquery.com in header section. Change YOur Function to this ..

          <script type="text/javascript" language="javascript">

              function fnClickCalc() {
          
                  var lbl1 = $("#lblFirstNo");
                  var lbl2 = $("#lblsecondNo");
                  var lbl3 = $("#lblResult"); 
          
                 lbl3.Text = lbl1.Text + lbl2.Text ; 
              }
          </script>
          
          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