Call ASP.NET codebehind from javascript (PageMethod)

The first thing to do is to add a ScriptManager to our page,
and tell it to accept page Methods.
<asp:ScriptManager ID="ScriptManager1" runat="server"

Next add the codebehind method to call, it must be static and have
the WebMethod attribute

public static void SetDimensions(int width, int height)
    //Method code

Finally call the method using PageMethods 

<script type="text/javascript">
    function setDimensions() {
        PageMethods.SetDimensions(width, height);

%d bloggers like this: