Click here to Skip to main content
Licence Ms-PL
First Posted 5 Aug 2010
Views 6,472
Bookmarked 7 times

How to Call the Code Behind Method in Javascript

By | 5 Aug 2010 | Article
Calling the Asp.net Code Behind method into Javascript
 
Part of The SQL Zone sponsored by
See Also

Introduction 

How to access the Code behind method into java script.

Background 

It will useful into some block of code in between to show the alert or confirmation message
 

Using the code

  Blocks of code should be set as style "Formatted" like this:

  <script language="javascript" type="text/javascript">
        function call_me()
        { 
        
           var Temp= confirm("Hit from ClientSide");
     
             if(Temp)
             {
             alert("True");     
              __doPostBack('btnHdn','onserverclick'); 
             }
             else
             {
             alert("false");
             } 
                
        }
    </script>
		
 From Button event 
<input type="button" runat="server" onclick="call_me();" id="btnClick" value="PRESS" /> 
 Calling this method into  java script function.
public partial class Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Call_Server(Object sender, EventArgs e)
    {
        Response.Write("Calling Server Side Event");
    }

}

 

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

PalaniEllappan

Architect

India India

Member

My interest areas are WCF,.net,Generics,Enterprise Library,Regular expressions,Silver light and Windows Workflow Foundation.Product Development and Architecture

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 3 PinmemberZiad Elmalki23:24 2 Jan '11  
GeneralMy vote of 1 Pinmemberdamiaan4:41 7 Aug '10  
GeneralMy vote of 1 Pinmemberj03x221:34 6 Aug '10  
GeneralMy vote of 1 PinmemberJoe Enos12:37 6 Aug '10  
GeneralMy vote of 2 PinmemberGil Fink3:14 6 Aug '10  
GeneralNon Functional Pinmemberinetfly1232:41 6 Aug '10  
General[My vote of 2] Looks like a Tips & Tricks PinmentorKunalChowdhury23:24 5 Aug '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 6 Aug 2010
Article Copyright 2010 by PalaniEllappan
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid