Thursday, August 29, 2013

JavaScript AJAX Function


This is the function which is need to add in the javascirpt file or page.
function standardAjax(inputvar, url, divid1, AjaxThread) {
var str, arr1, arr2, final_string;
var http = new Array;
document.getElementById(divid1).style.display = 'block';
try
{ http[AjaxThread] = new XMLHttpRequest(); }
catch (e) {
try
{ http[AjaxThread] = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) {
try
{ http[AjaxThread] = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
var params = inputvar;
http[AjaxThread].open("POST", url, true);
http[AjaxThread].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http[AjaxThread].setRequestHeader("Content-length", params.length);
http[AjaxThread].setRequestHeader("Connection", "close");
http[AjaxThread].onreadystatechange = function() {//Call a function when the state changes.
if (http[AjaxThread].readyState == 4 && http[AjaxThread].status == 200) {
str = http[AjaxThread].responseText;

if (str == null)
document.getElementById(divid2).style.display = 'none';

var strScript = str.split('');
eval(strScript[0]); // to run any script called up from ajax page
}

}
}
http[AjaxThread].send(params);
}

Points to remember:
1) inputvar ---> here we have to pass the parameters that we want to post on the page.
2) url -----> url of the page which we need to call.
3) divid1 -----> id of the div where we want to show the data that return from the page.
4) AjaxThread -----> integer value 1 or 2.

Example:-

standardAjax('var1=10&var2=sachin', 'location of page it is in our solution', 'id of div', 2);

Sunday, May 1, 2011

Defining and Accessing Oracle Connection in app.cong

Step 1:- Add a app.conf file to your windows project.

a) To do this go to solution explorer, right click over the project sln to add a new item, a Add New Item Dialog box appear in fort of you.

b) from Add New Item Dialog box choose Application Configuration File.

Step 2:- In app.conf file define Oracle Connection.

Ex:-








Step 3:- Code for accessing this define connection string in .cs page.

Ex:-
using System.Data.OracleClient;
OracleConnection con = new OracleConnection ( System.Configuration. ConfigurationManager.AppSettings["OracleConnection"].ToString());

Saturday, January 8, 2011

JavaScript to Find Position of element in form

function findPosX(obj)
{
var curleft = 0;
if(obj.offsetParent)
while(1)
{
curleft += obj.offsetLeft;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.x)
curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
var curtop = 0;
if(obj.offsetParent)
while(1)
{
curtop += obj.offsetTop;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.y)
curtop += obj.y;
return curtop;
}

Monday, January 3, 2011

Encryption and Decryption Function in JavaScript

function Decrypt(val)
{
val=unescape(val);
var len=val.length;
var newchar="";
var con=1;
var changer=10;
for(var i=0;i {
if(con%3==0)
changer=parseInt(changer)+2;
con++;
var ch=val.charCodeAt(i);
ch=parseInt(ch)-parseInt(changer);
newchar+=String.fromCharCode(ch);
}
return newchar;
}

function EncrptyData(Textval)
{
var a=Textval;
var newChar="";
var len=a.length;
var con=1;
var changer=10;
for(var k=0;k {
if(con%3==0)
changer=parseInt(changer)+2;
con++;
var ch=a.charCodeAt(k);
ch=parseInt(ch)+parseInt(changer);
newChar+=String.fromCharCode(ch);
}
return escape(newChar);
}

Javascript to add,delete and get browser cookie

//Javascript function to set browser Cookie at client side. The parameters are
c_name :- name of the cookie by which it is identified in browser.
value :- the value of the cookie to set in browser.
expiredays :- number of days to maintain the cookie in browser.

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

//Javascript function to get browser cookie at client side. The parameters are
c_name :- name of the cookie to get from browser.


function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1)
c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}

//Javascript funtion to delete browser cookie. The parameters are
cookie_name :- name of the cookie to be deleted from the browser.

function delete_cookie(cookie_name)
{
var cookie_date = new Date();
cookie_date.setTime(cookie_date.getTime()-1);
document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

Sunday, September 26, 2010

Detecting Tab Control on the textBox in window application in C#

private void Form1_Load(object sender, EventArgs e)
{
textBox1.Multiline = true;
}

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
{
MessageBox.Show("Tab Key is Pressed");
}
}

Friday, May 14, 2010

Resolving Datagrid View Scroll Problem while calling in thread

datagridview1.scrollBars=ScrollBars.None;
datagridview1.scrollBars=ScrollBars.Both;