Posts

Showing posts from January, 2011

Dynamically Add/Remove rows in HTML table using JavaScript

Image
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 issue...so now there is very easy sample for them...



Demo: Click here

Source code :(Html & JavaScript)
<HTML>
<HEAD>
<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";
cell1.appendChild(element1);

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

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

}

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 asp.net?" 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_;
else
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.

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

h…

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)
{
Response.Write("<table><tbody<tr>
<td>Decimal</td><td>ASCII character
</td><td>Hexadecimal</td></tr>\n");
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";
break;
case ' ':
display = "space";
break;
case '\n':
display = "\\n";
break;
case '\r':
displ…

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

Image
In 2nd part of the following post I show you how to open a new window in asp.net 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 =@"window.open(""{0}""…

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

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

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",
StringComparison.OrdinalIgnoreCase))
&&String.IsNullOrEmpty(windowFeatures))
{ 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 =@"window.open(""{0}"", ""{1}"",
""{2}"");"; }else { script =@&qu…