Archive

Author Archive

Adding UserControl Dynamically and Set Properties in Asp.net

November 8, 2010 1 comment

Validate your Javascript for Errors, checks

November 1, 2010 Leave a comment

Below are the software that can be used to validate your javascript  code, check for errors :

JSLint

http://www.jslint.com/ 

Scryptik javascript editor and validator

http://www.purpleoar.co.nz/scryptik/ 

Yaldex  

http://www.yaldex.com/JSFactory_Pro.htm

Insert JavaScript & CSS Dynamically

October 25, 2010 Leave a comment

Below is the code for Adding Javascript:

var headID = document.getElementsByTagName("head")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'http://www.somedomain.com/somescript.js';
headID.appendChild(newScript);

Below is the code for Adding CSS:

var headID = document.getElementsByTagName("head")[0];
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = 'FireFox.css';
cssNode.media = 'screen';
headID.appendChild(cssNode);

For More Details Refer:

http://bit.ly/9Q8bDK

http://bit.ly/9Q8bDK

Using Datejs – Open Source Javascript Date Library

October 18, 2010 Leave a comment

Datejs is an open source JavaScript Date library for parsing, formatting and processing

Overview & Download

http://code.google.com/p/datejs/

Getting Started

http://www.datejs.com/2007/11/27/getting-started-with-datejs/

Documentation

http://code.google.com/p/datejs/wiki/APIDocumentation

Examples:


Date.today()
Date.today().next().friday()
Date.today().is().november()
Date.today().addDays(1)
Date.today().addMonths(-3)
Date.october().fourth().sunday(
Date.today().between(startDate, endDate)  
Date.today().toString('d-MMM-yyyy')
Date.today().toShortDateString()
Date.getDayNumberFromName('sat')
Date.isLeapYear(2008)
Date.getDaysInMonth(2007, 9)

RegEx to Replace multiple line breaks in Asp.net

October 4, 2010 Leave a comment

Suppose the text is

“Long Description

With

Multiple

Line

Breaks”

Mulitple line breaks can be replaced with regex as follows:

Regex.Replace(yourlongtext, "[\r\n]+", " - - ");

Replace white spaces – blank spaces in string using Javascript

September 27, 2010 Leave a comment

Regex make our life simpler, and when used properly can create miracles. One such example  Regex is given below which replaces white spaces/blank spaces in string using javascript :

function ReplaceWhiteSpaces()
{
 var text = "Example to Replace white spaces in strings";
 text = text.replace(/\s/g, "-");
 alert(text);
}

Output : Example-to-Replace-white-spaces-in-strings

Regex Used : /\s/g

Get Client ID using Jquery

September 20, 2010 1 comment

When we are developing client side in asp.net, we need the id of the controls, but the IDs are merged with master page naming containers.

The id will look something like this

ctl00_MainContent_txtboxId
But using Jquery we can get id like this

$("#<%= <strong>txtboxId</strong>.ClientID %>")
$("[id$=_<strong> txtboxId</strong>]").attr("id")

You can also use the function

function GetClientID(id, context) {
var el = $("#" + id, context);
if (el.length < 1)
el = $("[id$=_" + id + "]", context);
return el;
}

Ex:

GetClientID("txtboxId").attr("id");

Or if I want to be specific about the container:
GetClientID("txtboxId",$("#wrapper")).attr("id");

For More Details Visit: http://www.west-wind.com/Weblog/posts/42319.aspx

Follow

Get every new post delivered to your Inbox.