Click here to Skip to main content
Click here to Skip to main content

How to Call the Code Behind Method in Javascript

By , 5 Aug 2010
 

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

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 3memberZiad Elmalki2 Jan '11 - 23:24 
GeneralMy vote of 1memberdamiaan7 Aug '10 - 4:41 
GeneralMy vote of 1memberj03x26 Aug '10 - 21:34 
GeneralMy vote of 1memberJoe Enos6 Aug '10 - 12:37 
GeneralMy vote of 2memberGil Fink6 Aug '10 - 3:14 
GeneralNon Functionalmemberinetfly1236 Aug '10 - 2:41 
General[My vote of 2] Looks like a Tips & TricksmentorKunalChowdhury5 Aug '10 - 23:24 

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

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