How to hide generated javascript file in visual studio code

In this post I am going to show you a cool trick in visual studio code. Let's suppose you are writing typescript code in visual studio code and you want to hide generated javascript code.

Create .vscode folder in your folder and then create settings.json file and paste following code

{ "files.exclude": { "node_modules":true, "**/.git": true, "**/.DS_Store": true, "**/*": true, "**/*.js": {"when": "$(basename).ts"}     } }

Calling page methods from javascript using ASP.NET AJAX

We can call page methods (static methods declared in scope of page) using MS Ajax framework for ASP.NET. That is how can we do it : 1) Drop ScriptManager control on page 2) Set EnablePageMethods property of ScriptManager control to true 3) Add static public method in page-behind code (or its parent class) and mark it with [System.Web.Services.WebMethod] attribute: 4) add following javascript code to it
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
   <title>Untitled Page</title>

   <script type="text/javascript">
   function CallMethod()

   function GetTime()
   function TimeOutHandler(result)
        alert("Timeout :" + result);
   /// <summary>
   /// Callback function invoked on failure of the page method 
   /// </summary>
   function ErrorHandler(result)
       var msg=result.get_exceptionType() + "\r\n";
       msg += result.get_message() + "\r\n";
       msg += result.get_stackTrace();
  GetTimeCallback = function (result) {
   /// <summary>
   /// Is called when server sent result back
   /// </summary>
   /// <param name="result">
   /// Result of calling server method, 
   /// string - server time 
   /// </param>
   if(result) {
        $get("resultDiv").innerHTML = result;

   <form id="form1" runat="server">
       <asp:ScriptManager EnablePageMethods="true" ID="MainSM" runat="server" ScriptMode="Release"
       <div id="resultDiv">
       <input value="GetTime" type="button" onclick="GetTime();" />
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
   protected void Page_Load(object sender, EventArgs e)

   public static string GetTime()
       return DateTime.Now.ToString();



  1. Your blog is very nice...
    visit my blog example

  2. Nice example, but not very practical. The C# code-behind method has to be static for the javascript PageMethods to find it. If you need to do things to controls on the page, the C# functions have to be dynamic, not static, or you have to do all sorts of workarounds to get the controls (i.e. Page page = new Page(), page.FindControl("myTextBox"), etc.) and those don't instantiate the actual properties on those controls, like .Text, for example. If you had a way to call a dynamic method, that would be da bomb...

  3. You can pass the control's clientid in PageMethods

  4. i want to do validation on client side but calling server side method in javascript. if you have any solution please email me on

  5. Doing the same as you did but my code is not working any reason for that. Can some one explain me why it is not working on my side

  6. helpful article.............

  7. 3 different ways to implement Ajax in Asp.Net applitacion


Post a Comment

Popular posts from this blog

How to get cell value of gridview using JQUERY

how to convert web page to pdf

Export Html to Pdf using iTextSharp(GridView)