Adding JavaScript to ASP NET controls

preview_player
Показать описание
If you are a foodie like me, I am sure you will enjoy the recipes on my friend's YouTube channel. If you find them useful, please subscribe and share to support her. She's really good at what she does.

Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

In this video we will discuss different options available to add JavaScript to ASP.NET server controls.

Adding JavaScript to ImageButton in ASP.NET :

The JavaScript that we want to execute in response to onmouseover and onmouseout events can also be present in separate JavaScript functions as shown below.
[form id="form1" runat="server"]
onmouseover="changeImageOnMouseOver();" onmouseout="changeImageOnMouseOut();" /]
[script type="text/javascript"]
function changeImageOnMouseOver()
{
}
function changeImageOnMouseOut()
{
}
[/script]
[/form]

Adding JavaScript to ASP.NET server control at runtime :

ASPX : Notice that in the declarative markup we removed onmouseover and onmouseout attributes

ASPX.CS :
protected void Page_Load(object sender, EventArgs e)
{
}

Adding JavaScript to ASP.NET Button onclick client event declaratively : With Button, LinkButton and ImageButton controls, OnClick attribute corresponds to server side click event. For this reason you cannot use OnClick attribute to add JavaScript that you want to execute in response to client side click event. The following code throws an error.

OnClick="return confirm('Are you sure you want to submit')"/]

With Button, LinkButton and ImageButton controls to associate JavaScript that you want to execute in response to client side click event use OnClientClick attribute as shown below.

OnClientClick="return confirm('Are you sure you want to submit')"/]

Adding JavaScript to ASP.NET Button onclick client event at runtime : If you are adding JavaScript at runtime, then you will have to use onclick.

ASPX :

ASPX.CS
protected void Page_Load(object sender, EventArgs e)
{
ImageButton1.Attributes.Add("onclick", "return confirm('Are you sure you want to submit');");
}
Рекомендации по теме
Комментарии
Автор

This was very clear and to the point. It explained/showed multiple ways to include functional JavaScript into the page.

stephenwebster
Автор

TY, another GREAT informative video !!
FYI readable typos !!
1) [changeImaageOnMouseOver()] should
2) [changeImaageOnMouseOut() ] should 'read' [changeImageOnMouseOut() ]

dnomyartnarg
Автор

Its really been very helpful to me.
Thanks a lot for making these videos.
When I visit youtube.com, I used to visit to your channel as well.
Thanks again Venkat Sir!.

csyadav
Автор

Thank you, this was an excellent lesson. Very clear and informative!!

rayreid
Автор

We also follow you from the Canary Islands. Thanks a lot for openning my eyes.

antoniosocorro
Автор

Awesome.  Towards the end, how come we can't specify the "onclientclick" attribute during the page load event programmatically? -- Why do have to use "clientclick" instead?

colerees
Автор

Venkat, I would love to see a N Tier Program with Javascript to MVC, you are the best teacher!!

MrJcyank
Автор

Thanks a lot Venkat, very useful list of JS. Greetings from Turkiye

salihcnar
Автор

Greeting from Ukraine, thanks a lot for your huge amount of work

prodazhatovarov
Автор

thanks a lot venkat for all this videos...it really gonna help me in my projects....regards Neha

nehadeshmukh
Автор

Sir please do videos on AJAX through JQUERY.

worldisone
Автор

Your videos are awesome. I learn a lot from them. Thank you so much for doing this.

HuzairBahadur
Автор

I have visual basic 2010 installed but there is now web application component. where I will find this??

sonalinarkar
Автор

I am using ASP.NET MVC. Is this tutorial help me ?

Escordes
Автор

Do you know how I could pass a javascript variable into asp.net .

jrwilliams
Автор

Thank you. This is exactly what I needed.

mandy
Автор

Thank you for the training videos and would like to request MVC/Entity Framework/Visual Studio 2017 version of this Javascript with ASP.NET playlist. Do you have updated versions on your DVD? If so, I'd be interested in buying it. You are the expert, but it looks like ASP.NET WebForms are falling out of favor as compared to MVC.

CodingSquid
Автор

thanks a lot sir for such wonderful videos.... how can I print a part or section of web form in asp. net using javascript(on a button click event)

SCHOOLBHSZOONIMAR
Автор

How to display message box center of the screen.

mehreentariq
Автор

Sir Please upload a video on N-Tier Program.

santhoshch