Using jQuery with ASP.NET
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.
Introduction to TypeScript?
Step by Step Explanation
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
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.
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
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.
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:
As it is evident in the name, you are able to run multiple
In order to start a TypeScript project, you need this.
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.
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.
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.