Image click event in jquery

Image click event in jQuery

In this post we are going to see how to get click event of image. This can be done by using either id jquery selector or css selector. We will see both the examples to get image click in jquery.

Image click event using id selector [jQuery]

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<title>Get Image click event</title>
<script type="text/javascript">
$(document).ready(function () {
$("#tulips").click(function () {
alert("Image click in jquery");
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<img src="Image/Tulips.jpg"  runat="server" id="tulips" alt="image click in jquery"/>
</div>
</form>
</body>
</html>

Image click event using css selector [jQuery]

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<title>Get Image click event</title>
<script type="text/javascript">
$(document).ready(function () {
$(".imagecss").click(function () {
alert("Image click in jquery");
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<img src="Image/Tulips.jpg"  runat="server" id="tulips" alt="image click in jquery" class="imagecss"/>
</div>
</form>
</body>
</html>

Convert Date to culture specific format

datetime culture
In C# we need to show date format as per culture.To convert datetime in culture specific format we need to use CultureInfo class in .ToString constructor with culture code like for US culture pass "en-US". We will see here few examples to format date as per culture.

Code to format date in US culture [C#]

using System;
 public class StringToDateTime
 {
   public static void Main()
   {
     var myDateTimeValue = "2012-01-16 15:02:26";
     DateTime myDateTime = DateTime.Parse(myDateTimeValue);
     var dateingddmmyy = myDateTime.ToString(new CultureInfo("en-US"));
     Console.Write(dateingddmmyy);
   }
 }

Code to convert date in sanskrit Indian culture [C#]

using System;
 public class StringToDateTime
 {
   public static void Main()
   {
     var myDateTimeValue = "2012-01-16 15:02:26";
     DateTime myDateTime = DateTime.Parse(myDateTimeValue);
     var dateingddmmyy = myDateTime.ToString(new CultureInfo("sa-IN"));
     Console.Write(dateingddmmyy);
   }
 }


Code to convert date in Swedish culture [C#]

using System;
 public class StringToDateTime
 {
   public static void Main()
   {
     var myDateTimeValue = "2012-01-16 15:02:26";
     DateTime myDateTime = DateTime.Parse(myDateTimeValue);
     var dateingddmmyy = myDateTime.ToString(new CultureInfo("sv-SE"));
     Console.Write(dateingddmmyy);
   }
 }

Convert date to ""dd/mm/yyyy" format C#

format datetime in dd/mm/yyyy

In c# we need to convert datetime in different formats.In this post we will see how to get datetime in "dd/mm/yyyy" format.To parse datetime in "dd/mm/yyyy" format we need to use string formatter "dd/mm/yyyy" in .ToString() constructor.

Code to get datetime in dd/mm/yyyy format [C#]

using System;
 public class StringToDateTime
 {
   public static void Main()
   {
     var myDateTimeValue = "2012-01-16 15:02:26";
     DateTime myDateTime = DateTime.Parse(myDateTimeValue);
     var dateingddmmyy = myDateTime.ToString("dd/mm/yyyy");
     Console.Write(dateingddmmyy);
   }
 }
 

Get dropdown selected item onchange in jQuery

get dropdown list selected item onchange in jquery
When using dropdown list in asp.net application, we need to get value of selected item on onchange event of dropdown. In this post we will see example of how to get value of selected item using onchange event of dropdown.

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<title>Get dropdown value</title>
<script type="text/javascript">
$(document).ready(function () {
$("#topics").change (function () {
var text = $("#topics option:selected").text();
var value = $("#topics option:selected").val();
alert("Selected text=" + text + " Selected value= " + value);
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="topics" runat="server">
<asp:ListItem Text="C#" Value="1"></asp:ListItem>
<asp:ListItem Text="jQuery" Value="2"></asp:ListItem>
<asp:ListItem Text="ASP.NET" Value="3"></asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>
Output