Visual Studio Code Jquery

Using jQuery with ASP.NET

Studio

This code searches for a class named inputMail (the dot means it is a class where we are looking for). When Jquery found that object it will check if it is being clicked. When it is being clicked it executes the function. So inside that function we can let the button do a little trick. 130+ jQuery code snippets for Visual Studio 2012 & 2013.https://github.com/kspearrin/Visual-Studio-jQuery-Code-Snippetshttp://visualstudiogallery.msdn.micros. The following steps illustrate how to download and install the Syncfusion Blazor Template Studio with the Code Generator extension from the Visual Studio Marketplace. Note: Syncfusion Blazor Code Generator was shipped within the Syncfusion Template Studio. Download the Syncfusion Blazor Template Studio from the Visual Studio Marketplace.

As this post is about 'using jQuery with ASP.NET' so we will not be looking into 'What is jQuery' and 'How to use jQuery' assuming you know basics of jQuery. If not, then please read 'Learn how to use jQuery?'

To begin with using jQuery with ASP.NET, first download the latest version the jQuery library from jQuery website and unzip or copy the file in your project or Visual studio solution. Microsoft Visual studio 2010 and 2012 include jQuery by default and provide intellisense to use jQuery. Assuming that you have placed the library in Script folder, add this in the head of your ASP.NET page (simple or master). (Its a good practice to keep your all js file under Script folder).

Or you can directly refer them using various CDNs. Put this line of code in head section of ASP.NET Page.

In the above code, I have not used 'http' protocol while referencing jQuery from Google CDN. Its not a mistake rather always use protocol less URL for referencing jQuery.

After this setup, you can use jQuery in your ASP.NET page. Let's see a demo.

Show alert window on click of ASP.NET Button.

Assuming a ASP.NET button with ID 'btnSubmit ' is placed on the page.

And now bind the click event to ASP.NET Button in document.ready section.

In above jQuery code block, we have attached click event to the button using ID selectors. Read more about other jQuery selectors and how to use them.

Below is a list of useful jQuery code example for ASP.NET controls that we use on daily basis. One thing, while creating object of any ASP.NET control, always use ClientID. As when Master pages are used then the ID of the ASP.NET controls is changed at run time. Read more here. But with ASP.NET 4.0, this is changed and now you have control over the Client ID using ClientIDMode property.

Get label value:

Set label value:

Get Textbox value:

Set Textbox value:

Get Dropdown value:

Set Dropdown value:

Get text of selected item in dropdown:

Get Checkbox Status:

Check the Checkbox:

Uncheck the Checkbox:

Get Radiobutton Status:

Check the RadioButton:

Uncheck the RadioButton:

Disable any control:

Enable any control:

Make textbox read only:

I had already posted many ASP.NET related post and below you find links some useful posts.

Feel free to contact me for any help related to jQuery, I will gladly help you.

Code

Introduction to TypeScript?

First and foremost, TypeScript is a modern day programming language. We use this programming language for large-scale JavaScript application development. We can refer to it as a typed superset of JavaScript.

The best thing about TypeScript is that you will gain access to features from recent versions of ECMAScript as well. And you may use features beyond the scope of that as well. When you compile TypeScript, you will be able to produce a version of JavaScript which is safe across all platforms.

Step by Step Explanation

1. Prerequisite

Before we kick start TypeScript project, you must set up Node JS environment in your system. If you don’t have Node JS setup then follow the given link to set up Node JS development environment in your system.

Once you are done setting up Node JS make sure it is working fine by typing the below command

2. Install Visual Studio Code

I am going to use visual studio code editor to work on TypeScript in our project.

Click here to install visual studio code.

3. Setup TypeScript using NPM

Once you are done with the installation of visual studio code, you need to create a folder which is easy to access. You can give whatever name that you find fitting. I have given the name typescript-project. Now you need to open this file in visual studio code.

You need to create two new files named index.html and app.ts in the TypeScript project folder.

Open the index.html and just add a regular HTML5 boilerplate. You need to make
sure that it has a script tag that appears right before the closing body tag.

index.html

Visual Studio Code Jquery Debugging

The script tag points to app.js. However, app.js is non-existent at this point. It will get created as soon as we compile the TypeScript.

Visual Studio Code Jquery

Build TypeScript Package Manager

When it comes to projects developed in TypeScript, we can take the help of a package manager like NPM. NPM helps us in several ways. First and foremost, you will be able to execute the project in a virtual environment supported by the lite server. It also helps turn the compilation of TypeScript to JavaScript into an automated process. Last but not least, NPM helps us to keep a tab on dependencies.

Open TypeScript terminal within VS code, press shift + cmd + ‘ inside VS Code. Run the below command.

You will have to input the name of the project before everything else. You may refer to the code below to see the defaults. You don’t need to worry about the defaults at all. You will have to fill up a couple of details including the description and the author. You will also have to input the entry point to your primary JS file.

Here, in this case, app.js is our entry point.

Once you are done with all the key setup parameters, you will be intimated that you are all set to make some changes to package.json. If everything looks fine, press enter once again. You will be able to see the package.json file in VS Code.

4. Testing the Package

In order to see if the package is working or not, you need to enter the below command in the terminal.

Code

You will be greeted with a text message if the testing has been successful.

5. Adding Dependencies

We have just initialized the basic package for the project. It’s time for us to add some dependencies. And it is referred to as dev dependencies. As far as packages are concerned, there are two types of dependencies. The first type is used in development as in TypeScript. The second type is used production as in jQuery.

We are going to install the following dependencies as dev dependencies:

Concurrently

As it is evident in the name, you are able to run multiple
commands concurrently.

Typescript

In order to start a TypeScript project, you need this.

Lite-server

We are referring to a development only node server here, and it is lightweight in nature. When you alter something in JavaScript or HTML, it refreshes itself. And the changes made to the CSS will be injected via sockets.

We use the below command to install an NPM package.

If you wish to install more than one NPM packages at a time, you achieve the same by separating the packages with space. You need to run the following command to install dev dependencies.

Your package.json file will be updated automatically.

Yes, we have made some good progress as far as our project is concerned. But TypeScript compilation will not happen just yet. We are in need of a tsconfig.json file for the same. We also need to come up with a few extra commands for the project.

We need to run the given below command before we try to configure the scripts. First, you will be greeted by a “Successfully created a tsconfig.json file” message. Now when you open the VS Code you will be able to spot the tsconfig.json file.

6. Setting up the scripts

We have test command in the possession of our script object. When we utilize the npm test, the test command provides output. But we are going to add some additional commands that define our lite-server, TypeScript Compiler Watcher. And a start command will concurrently run several things and update the lite-server in real-time as well. As a result, the development process becomes so much easier.

So let’s take a look at the latest package.json file with script commands.

In the scripts object, we have defined the compiler and server as follows.

  • “lite”:”lite-server”Lite server
  • “tsc”:”tsc”TypeScript compiler
  • “Tsc:w”:”tsc-w”TypeScript in watch mode

We have also defined our stand command as well.

7. TypeScript Compiler in Watch Mode

Concurrently has application at this stage. The start command will take the responsibility of concurrently running lite server and TypeScript Compiler in watch mode. Once after saving the package.json, you need to start the project. And it is the final, step. Enter below command in the terminal. The start command exists in the script object will be initiated.

You will be able to see the Watching files if you haven’t made any errors in the setup. And Chrome should have already launched the project in watch mode. And all the TypeScript files will be compiled producing JavaScript output. All of a sudden you will notice the existence of an app.js file which wasn’t there before. The compiler has generated it while generating the JavaScript output.

Now we are going to make some changes in app.ts. And this should trigger some action in the terminal. You will see the lite server and the TypeScript Compiler being part of the action.

At this point onwards, whenever we alter app.ts and save it, the compiler get into action as it will convert the TypeScript into JavaScript. You can see it in app.js. Same can be witnessed in the updates happening in the lite server as well.

Studio

NPM is really convenient. For instance, once you have setup package.json, you can copy the package. And then you can run the command npm install – it will initiate the installation of all the dependencies. Now run npm start, you already have the project setup ready. You are all set to write your code! However, you should initialize tsconfig with
tsc –init before you attempt that.