How to use javascript in C# code


How to use javascript in C# code?

simpsons_wikia_com

image credit:wikia.com

The newbie developer always get confused when he is asked: How to use javascript in C# code?
This sort of problem occurs due to not considering the javascript as an amazing client side script that is not only easier but also provides the facility for web application developer to bring the greatest end user interaction.
All those drag and drops , fancy page elements, smooth data fetching are possible by including javascript in our applications.
What is better than the fact that JQuery is a library of javascript code that has made web programming much easier and glittering and it is open source and freely available. So give me a smile 🙂
The power of AJAX totally outclasses all the contemporary platforms because it deals with the back end data sources very well.
Inserting the javascript code in C# in asp.net is very easy and it does not require top notch programming skills.

Lets start it

In order to use the facility provided by asp.net to include javascript functions, we have several techniques but personally, I would prefer the .net methods to call the javascript code which are:

RegisterStartupScript and RegisterClientScriptBlock

Make a habit of generally avoiding RegisterClientScriptBlock method that places the JavaScript at the bottom of the ASP.NET page.This is because, letting the script to read all the markup or controls from top to bottom of a page is beneficial to get the necessary things from the controls or markup. The RegisterStartupScript method places the javascript on top of the page so that no controls are invisible to it.

Example program

js in csharp

Output

js in csharp output

Syed Adeel Ahmed
Syed Adeel Ahmed
Analyst, Programmer, Educationist and Blogger at Technofranchise
Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.

Published by

Syed Adeel Ahmed

Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.

Leave a Reply