Skip to main content

Posts

Javascript: Function to get Cookies values

function getCookiesValue(objCkNm) { var beginindex, endindex, result, num; num = objCkNm.length; beginindex=document.cookie.indexOf(objCkNm) + num +1 ; endindex=beginindex; //while we haven't hit ";" and it's not end of cookie while (document.cookie.charAt(endindex)!=";" && endindex <= document.cookie.length) endindex++ //result contains "JavaScript Kit" result=document.cookie.substring(beginindex,endindex) return result; }

Javascript: function to check that number is numeric

function IsNumeric(strString) { // check for valid numeric strings var strValidChars = "0123456789.-"; var strChar; var blnResult = true; if (strString.length == 0) return false; // test strString consists of valid characters listed above for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult; }

Javascript: Email Validation function

function ValidateEmail(str) { var at="@" var dot="." var lat=str.indexOf(at) var lstr=str.length var ldot=str.indexOf(dot) if (str.indexOf(at)==-1) { alert("The eMail address '@' convention appears to be invalid.") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) { alert("The eMail address '@' convention appears to be invalid.") return false } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ alert("The eMail address 'dot' convention appears to be invalid.") return false } if (str.indexOf(at,(lat+1))!=-1) { alert("The eMail address '@' convention appears to be invalid.") return false } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) { alert("The eMail address 'dot' convention appears to be invalid.") return false } if (str.indexOf(dot,(lat+2))==-1) { aler...

DataGrid Export to excel file

private void ExportGridToExcel(DataGrid grdGridView, string fileName) { Response.Clear(); Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", fileName)); Response.Charset = ""; Response.ContentType = "application/vnd.xls"; StringWriter stringWrite = new StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); grdGridView.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); }

Read a File

1. Map The Server Path string strFileName = Server.MapPath("partnership_msg.txt"); 2. Here is the code to Read Text File From Path "partnership_msg.txt" into streamReader StreamReader sr = new StreamReader(new FileStream(strFileName,FileMode.Open, FileAccess.Read)); 3. Read the content from the StreamReader into string variable strBody = sr.ReadToEnd(); 4. Close the Streamreader sr.Close();

how to resize image and show resized image

step 1: Take a image button and assign ImageUrl is equal to original Image Path Eg :- Image.ImageUrl = "image/originalImage.jpeg" Step 2: Then On pageLoad write the code:- Image.ImageUrl = "view.aspx?imgUrl =" + Image.ImageUrl + "&Width=100&Height=100"; step 3: write the Following Coding on the view.aspx Page:- private void Page_Load(object sender, System.EventArgs e) { string url="../Products/image/imageNot.jpg"; int Weight=60,Height=60; if(Request.QueryString["URL"]!=null) { url = Request.QueryString["URL"].ToString(); Weight = Convert.ToInt32(Request.QueryString["Width"].ToString()); Height = Convert.ToInt32(Request.QueryString["Height"].ToString()); } Resize(url,Weight,Height); } public void Resize(string strPath, int Weight, int Height) { string strFile = strPath.Substring(strPath.LastIndexOf("/")+1); string urlPhysical = HttpContext.Current.Server.MapPath(st...