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;

Adding Checkbox in Column Header of DataGridView in .net using C#

private void Form_Load(object sender, EventArgs e)
{
c1 = new DataGridViewCheckBoxColumn();
c1.Name = " selection";
c1.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
this.dataGridView1.Columns.Add(c1);

this.dataGridView1.Rows.Add();
this.dataGridView1.Rows.Add();
this.dataGridView1.Rows.Add();
this.dataGridView1.Rows.Add();

ckBox = new CheckBox();
//Get the column header cell bounds
Rectangle rect =
this.dataGridView1.GetCellDisplayRectangle(0, -1, true);
ckBox.Size = new Size(16, 16);
//Change the location of the CheckBox to make it stay on the header
ckBox.Location = rect.Location;
ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);
//Add the CheckBox into the DataGridView
this.dataGridView1.Controls.Add(ckBox);
}

void ckBox_CheckedChanged(object sender, EventArgs e)
{
for (int j = 0; j < this.dataGridView1.RowCount; j++)
{
this.dataGridView1[0, j].Value = this.ckBox.Checked;
}
this.dataGridView1.EndEdit();
}

Saturday, November 14, 2009

Creating Still background image for a web page through CSS

If you want a background image that remains still while scrolling the web page window, you can do it in few simple steps.

Create a Class in style-sheet having properties:-
1)background-attachment : fixed;
2)background-repeat : no-repeat;
3)background-image : URL (URL of the image);

now use that class in the body tag.

Monday, November 9, 2009

changing CSS class name of an html tag through javascript.

if we want to change the class name from "abc" to "xyz" of a div tag having attribute id="a" through javascript and these classes are defined in stylesheet then following is the javascript code.

javascript code:

function ChangeClass(id,class)
{
document.getElementById(id).className=class;
}

ChangeClass('a','xyz');

Thursday, July 2, 2009

converting number in numeric word formate in Oracle

select to_char(to_date(&num,'Jsp'),'Jsp') from dual;
num=123;
output will be one hundred twenty-three;

this statement convert the number formate in numeric word formate.