filmov
tv
Adding JavaScript to ASP NET controls

Показать описание
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');");
}
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');");
}
Комментарии