Wednesday, 11 June 2014

How to convert a given word to pascal casing in ASP.NET ?

Today I am going to explain about how to convert a given word to pascal casing.

What is Pascal Casing?

The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.

For example

Sachin Tendulkar

In the above example we have capitalized the first characters in the both the words Sachin and Tendulkar.

At most times the user may not show interest in typing the first letter of his name in capital when he is entering his name in a text box. At that time we need a code in the backend which can automatically convert the text to capitals.

Take an asp textbox.

<asp:TextBox Id=”txtName” runat=”server”>

Call this textbox in the aspx.cs page.

Now write the following code in the aspx.cs page to convert the first letter each subsequent concatenated word to capitals.

System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(txtName.Text.ToLower());


This code automatically converts the starting letter of each word to capitals.

Wednesday, 16 April 2014

How to set focus on first or particular textbox during page load using JQuery in ASP.NET

In this article I will explain how to set focus on first or particular textbox during page load using JQuery in ASP.NET

In this scenario we need to write code for focus on first or particular textbox.

Example 1: Focus First Textbox

<script type="text/javascript">
$(document).ready(function () {
$('input:text:first').focus();
});
</script>

Example 2: Focus Particular Textbox

<script type="text/javascript">
$(document).ready(function () {
$(#txtFirstName').focus();
});
</script>

Below is the total code Textbox focus.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Set focus in particular textbox </title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>

// Focus first textbox

<script type="text/javascript">
$(document).ready(function () {
$('input:text:first').focus();
});
</script>

(Or)

// Focus Particular textbox

<script type="text/javascript">
$(document).ready(function () {
$(#txtFirstName').focus();
});
</script>

</head>
<body>
<form id="form1" runat="server">
<table align="Center">
<tr>
<td colspan="2">Set focus in particular textbox or First textbox
</td>
</tr>
<tr>
<td colspan="2" height="20px"></td>
</tr>
<tr>
<td>FirstName :</td>
<td>
<asp:TextBox runat="server" ID="txtFirstName" /></td>
</tr>
<tr>
<td>LastName :</td>
<td>
<asp:TextBox runat="server" ID="txtLastName" /></td>
</tr>
<tr>
<td>Location :</td>
<td>
<asp:TextBox runat="server" ID="txtLocation" /></td>
</tr>
<tr>
<td>City :</td>
<td>
<asp:TextBox runat="server" ID="txtCity" /></td>
</tr>
<tr>
<td>
<asp:Button runat="server" ID="btnSave" Text="Save" />
</td>
<td>
<asp:Button runat="server" ID="btnCancel" Text="Cancel" />
</td>
</tr>
</table>
</form>
</body>

</html>

Date picker (Or) Datepicker Examples

How to disable particular days in DatePicker on ASP.NET using JQuery


In this article I will explain how to disable particular days in Datapicker on ASP.NET using JQuery.


Sample code :

<script type="text/javascript">
var Alldays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
var disableParticularDates = ["2014/04/16", "2014/05/20", "2014/06/24", "2014/04/18", "2014/05/21", "2014/06/28"]; // yyyy/MM/dd
var disableParticulaDays = ["Saturday", "Sunday"];
function ShowDisableDays(date) {
ymd = date.getFullYear() + "/" + ("0" + (date.getMonth() + 1)).slice(-2) + "/" + ("0" + date.getDate()).slice(-2);
day = new Date(ymd).getDay();
if ($.inArray(ymd, disableParticularDates) < 0 && $.inArray(Alldays[day], disableParticulaDays) < 0) {
return [true, "enabled", "Book Now"];
} else {
return [false, "disabled", "Sold Out"];
}
}
$(function () {
$("#datepicker").datepicker({ beforeShowDay: ShowDisableDays });
});
</script>

Output: