var conn = '<%=ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString %>'
alert(conn);
var v1 = '<%=ConfigurationManager.AppSettings["var1"].ToString() %>'
var v1 = '<%=ConfigurationManager.AppSettings["var1"] %>'
<%$AppSettings:Title%>
alert(v1);
Blog that contains articles about new technologies related or not with programming. I will describe and solves some problems that I encounter in my career. ASP .NET, AJAX, Javascript, C++, C# and SQL are some of the subjects that will appear.
29 March 2012
28 March 2012
restrict textbox to allow only numerics
function numerics()
{
key = String.fromCharCode(window.event.keyCode);
if (!(key >= '0' && key <= '9')) window.event.keyCode=0;
}
<asp:TextBox ID="txt1" Text="" runat="server" onkeypress=" return numerics();"></asp:TextBox>
function isAlpha(keyCode)
{
return ((keyCode >= 65 && keyCode <= 90) || keyCode == 8||keyCode==37||keyCode==39||keyCode==9||keyCode==46)
}
function isNum(keyCode)
{
return((keyCode < 105 && keyCode > 96)||(keyCode < 57 && keyCode > 48) || keyCode == 8||keyCode==37||keyCode==39||keyCode==9||keyCode==46)
}
<asp:TextBox ID="txtUserName" runat="server" onkeydown = "return isAlpha(event.keyCode);" onpaste = "return false;" Width="130px"></asp:TextBox>
public static bool IsNumeric(String strVal)
{
Regex reg = new Regex("[^0-9-]");
Regex reg2 = new Regex("^-[0-9]+$|^[0-9]+$");
return (!reg.IsMatch(strVal) && reg2.IsMatch(strVal));
}
{
key = String.fromCharCode(window.event.keyCode);
if (!(key >= '0' && key <= '9')) window.event.keyCode=0;
}
<asp:TextBox ID="txt1" Text="" runat="server" onkeypress=" return numerics();"></asp:TextBox>
function isAlpha(keyCode)
{
return ((keyCode >= 65 && keyCode <= 90) || keyCode == 8||keyCode==37||keyCode==39||keyCode==9||keyCode==46)
}
function isNum(keyCode)
{
return((keyCode < 105 && keyCode > 96)||(keyCode < 57 && keyCode > 48) || keyCode == 8||keyCode==37||keyCode==39||keyCode==9||keyCode==46)
}
<asp:TextBox ID="txtUserName" runat="server" onkeydown = "return isAlpha(event.keyCode);" onpaste = "return false;" Width="130px"></asp:TextBox>
public static bool IsNumeric(String strVal)
{
Regex reg = new Regex("[^0-9-]");
Regex reg2 = new Regex("^-[0-9]+$|^[0-9]+$");
return (!reg.IsMatch(strVal) && reg2.IsMatch(strVal));
}
21 March 2012
check all checkboxes in a form
$(document).ready(function() {
$('#chkAll').click(
function() {
$("INPUT[type='checkbox']").attr('checked', $('#chkAll').is(':checked'));
});
});
$('#chkAll').click(
function() {
$("INPUT[type='checkbox']").attr('checked', $('#chkAll').is(':checked'));
});
});
checkbox list javascript validation
function valid()
{
var chkBoxList = document.getElementById('<%=CheckBoxList11.ClientID %>');
var chkBoxCount= chkBoxList.getElementsByTagName("input");
var k=0;
for(var i=0;i<chkBoxCount.length;i++)
{
if(chkBoxCount[i].checked)
k++;
}
if(k==0)
alert("select any item");
return false;
}
{
var chkBoxList = document.getElementById('<%=CheckBoxList11.ClientID %>');
var chkBoxCount= chkBoxList.getElementsByTagName("input");
var k=0;
for(var i=0;i<chkBoxCount.length;i++)
{
if(chkBoxCount[i].checked)
k++;
}
if(k==0)
alert("select any item");
return false;
}
13 March 2012
Remove duplicates from an interger array
int[] a = { 1, 3, 2, 5, 6, 1, 2, 3 };
string s =",";
for (int i = 0; i < a.Length - 1; i++)
{
if (!s.Contains("," + a[i].ToString() + ","))
{
s += "," + a[i].ToString() + ",";
}
}
string ss = s.Replace(",,",",");
string sss = ss.Substring(1,ss.Length-2).Trim();
string[] aa = ss.Split(',');
int[] n=new int[ss.Split(',').Length-2];
for (int i=1;i<aa.Length-1;i++)
{
if (aa[i].Replace(",", "")!="")
n[i-1] = int.Parse(aa[i].Replace(",",""));
}
return n;
string s =",";
for (int i = 0; i < a.Length - 1; i++)
{
if (!s.Contains("," + a[i].ToString() + ","))
{
s += "," + a[i].ToString() + ",";
}
}
string ss = s.Replace(",,",",");
string sss = ss.Substring(1,ss.Length-2).Trim();
string[] aa = ss.Split(',');
int[] n=new int[ss.Split(',').Length-2];
for (int i=1;i<aa.Length-1;i++)
{
if (aa[i].Replace(",", "")!="")
n[i-1] = int.Parse(aa[i].Replace(",",""));
}
return n;
07 March 2012
array in javascript
<p id="div_p"></p>
var array = ["S", "V", "B"];
document.getElementById("div_p").innerHTML = array
var arrIDs=new Array();
arrIDs.push(e);
document.getElementById("div_p").innerHTML=arrIDs.join(',');
var arr = new Array(3);
arr[0] = "a";
arr[1] = "b";
arr[2] = "c";
var array1 = new Array("S", "V", "B");
//for object
var person = {firstName:"John", lastName:"Doe", age:46};
At position 2, add the new items, and remove 1 item:
The result of fruits will be:
var array = ["S", "V", "B"];
document.getElementById("div_p").innerHTML = array
var arrIDs=new Array();
arrIDs.push(e);
document.getElementById("div_p").innerHTML=arrIDs.join(',');
var arr = new Array(3);
arr[0] = "a";
arr[1] = "b";
arr[2] = "c";
var array1 = new Array("S", "V", "B");
//for object
var person = {firstName:"John", lastName:"Doe", age:46};
At position 2, add the new items, and remove 1 item:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 1, "Lemon", "Kiwi");
The result of fruits will be:
Banana,Orange,Lemon,Kiwi,Mango
Subscribe to:
Posts (Atom)