Showing posts from January, 2011

Dynamically Add/Remove rows in HTML table using JavaScript

This is very often for web developer when we need to use dynamically generate HTML table using JavaScript. I have found frequent request in various forum about this now there is very easy sample for them...

Demo: Click here

Source code :(Html & JavaScript)
<TITLE> Add/Remove dynamic rows in HTML table </TITLE>
<SCRIPT language="javascript">
function addRow(tableID) {

var table = document.getElementById(tableID);

var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";

var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount + 1;

var cell3 = row.insertCell(2);
var element2 = document.createElement("input");
element2.type = "text";


function deleteRow(tableID) {
try {
var table = document.getElementByI…

Get URL Parameters (QueryStrings) using Javascript

Today I have got a request from a newbie .."How to get value from Querystring using Javascript in" So I want to share with you ....

Unfortunately there is no method in JavaScript for parsing the querystring to get the value. So we try with regular expression to solve this problem..

JavaScript method for get URL parameter(QueryStrings)

function getQuerystring(key, default_)
if (default_==null) default_="";
key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
var qs = regex.exec(window.location.href);
if(qs == null)
return default_;
return qs[1];
}The following javascript code snippet facilitates Javascript's built in regular expressions to retrieve value of the key. Optionally, you can specify a default value to return when key does not exist.

The getQuerystring function is simple to use. Let's say you have the following URL:


How to generate ASCII Table

Very recently I get some request about ASCII code generate.
So that I share with this code...

using System;
using System.Web.UI;

public partial class _Default : Page
protected void Page_Load(object sender, EventArgs e)
<td>Decimal</td><td>ASCII character
int min = 0;
int max = 128;
for (int i = min; i <>// Get ascii character.
char c = (char)i;

// Get display string
string display = string.Empty;
if (char.IsWhiteSpace(c))
display = c.ToString();
switch (c)
case '\t':
display = "\\t";
case ' ':
display = "space";
case '\n':
display = "\\n";
case '\r':

Open new window with Response.Redirect() in 3rd part

In 2nd part of the following post I show you how to open a new window in using "ResponseHelper "class. Now today I want to share another approach with "Extension method".

Third approach(Extension method)
publicstaticclassResponseHelper {publicstaticvoid Redirect(thisHttpResponse response,string url,string target,string windowFeatures) {if ((String.IsNullOrEmpty(target) || target.Equals("_self",
StringComparison.OrdinalIgnoreCase)) && String.IsNullOrEmpty(windowFeatures)) { response.Redirect(url); }else { Page page = (Page)HttpContext.Current.Handler;if (page ==null) {thrownew InvalidOperationException("Cannot redirect to new window outside
Page context."); } url = page.ResolveClientUrl(url);string script;if (!String.IsNullOrEmpty(windowFeatures)) { script =@"""{0}""…

Open new window with Response.Redirect() in 2nd part

In my previous post I show you how to open a new window in using "".

Second approach(Using ResponseHelper class)

publicstaticclassResponseHelper {publicstaticvoid Redirect(string url, string target,
string windowFeatures) {HttpContext context =HttpContext.Current;if ((String.IsNullOrEmpty(target) || target.Equals("_self",
{ context.Response.Redirect(url); }else {Page page = (Page)context.Handler;if (page ==null) {thrownewInvalidOperationException("Cannot redirect to new window outside
Page context."); } url = page.ResolveClientUrl(url);string script;if (!String.IsNullOrEmpty(windowFeatures)) { script =@"""{0}"", ""{1}"",
""{2}"");"; }else { script =@&qu…