Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to Call the Code Behind Method in Javascript

0.00/5 (No votes)
5 Aug 2010 1  
Calling the Asp.net Code Behind method into Javascript

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here