Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Friday, October 14, 2011

Get selected checkbox value of ASP.NET GRID VIEW using JavaScript

<script language="javascript" type="text/javascript">

function GetSelected(objchk, HId) {
var hdnIds = document.getElementById("<%= hdnIds.ClientId %>");

if (hdnIds.value.length == 0) {
hdnIds.value = ",";
}

if (objchk.checked == true) {
hdnIds.value = hdnIds.value + HId + ",";

}
else {

hdnIds.value = hdnIds.value.replace("," + HId + ",", ",")
}
}
</script>






    'Bind this function like     On GridView's RowDataBound Event.
Private Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
Dim chkSelect As CheckBox = CType(e.Row.FindControl("chkSelect"), CheckBox)
If Not chkSelect Is Nothing Then
chkSelect.Attributes.Add("onclick", "GetSelected(this,'" & DataBinder.Eval(e.Row.DataItem, "HId").ToString() & "');")
End If
End Sub
'Now you have comma seperated values of HIds in hdnIds hidden field which you can use accordingly

Wednesday, October 12, 2011

Find post back control with JavaScript

<script language="javascript" type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
var PostBackCtrl;
function BeginRequestHandler(sender, e) {
PostBackCtrl = e.get_postBackElement();
}

function EndRequestHandler(sender, e) {

if (PostBackCtrl.id.toLowerCase().indexOf("yourcontrolname") > 0 ) {
//This is your control which made post back
//write your code here
}
}
</script>

Tuesday, September 20, 2011

TRIM STRING IN JAVASCRIPT

            function trimAll(sString) {
while (sString.substring(0, 1) == ' ') {
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length - 1, sString.length) == ' ') {
sString = sString.substring(0, sString.length - 1);
}
return sString;
}

Saturday, April 11, 2009

Open Model Popup Window In JavaScript

function OpenModelPopupWindow(Path,Height,Width)
{

var ParmA = '';
var MyArgs = new Array(ParmA);
var w = screen.availWidth;
var h = screen.availHeight;
var Wdth = (w-Width);
var Hgt = (h-Height);

var WinSettings = "help:no;center:yes;resizable:no;dialogHeight:" + Hgt +"px;dialogWidth:" + Wdth + "px;status=no;"

window.showModalDialog(Path,MyArgs, WinSettings );



}

Saturday, April 4, 2009

Get Property In Javascript

< script language=" javascript " type=" text/ javascript ">
var StudentName=' < % = StudentName % > ';
< / script>

Tuesday, March 17, 2009

How to find if variable exist or null in javascript ?

When you want to know if the variable is null then you can use :

if ( null == var ) // with type casting
if ( null === var ) // without type casting

When you want to check existance of variable you can use :


if ( typeof var != ‘undefined’ ) // Any scope

Monday, March 9, 2009

Restrict length of multiline textbox in asp.net

function checkMaxLength( txt,e, length )
{

var mLen = txt[ " MaxLength " ];
if(null == mLen)
mLen = length;

var maxLength = parseInt ( mLen );
if(!isSpecialCharacters( e ))
{
if(txt.value.length > maxLength-1)
{
if(window.event)//for Internet Explorer
e.returnValue = false;
else// For Firefox
e.preventDefault();
}
}
}

function isSpecialCharacters(e)
{
if(e.keyCode !=8 && e.keyCode!=46 && e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=39 && e.keyCode!=40)
return false;
else
return true;
}

add this in code behind file of the control

onkeyDown="checkMaxLength( this ,event ,'100' );"

Thursday, February 19, 2009

Get Query String In JavaScript With Split

< script type= "text/javascript" >

function querySt(qsFind)
{
qs = window.location.search.substring(1);

str = qs.split("&"); //Split Query String

for (i=0 ; i < str.length ; i++)
{

cs = str[i].split("="); /Split Individual Query String with =
if (cs[0] == qsFind) //Check for particular query string and if found return value
{
return cs[1];
}
}
}


< / script >

var Ledger_Id = querySt("Ledger_Id");

Wednesday, January 28, 2009

Tuesday, December 2, 2008

Exception / Error Handling In Javascript

< script language = "JavaScript" >
try
{
var I = 10;
var J = 0;
var K = I/J;
}
catch ( e )
{
alert("An exception occurred in the script. Error name: " + e.name
+ ". Error message: " + e.message);
}
< / script >

Monday, November 24, 2008

Javascript to open popup window

< script type=" text/javascript " >

var w = screen.availWidth; //For Screen Width
var h = screen.availHeight; //For Screen Height
var Width = (w-100); //
var Height = (h-100);
var left = (w-Width)/2;
var top = (h-Height)/2;

window.open(Path, 'NameOfWindow', 'width='+ Width +', height='+ Height +',top='+ top +',left='+ left +', menubar=no, resizable=no,scrollbars=yes')


< / script >

Saturday, November 8, 2008

Javascript on asp.net page

Suppose you want to call some javascript on click of any asp.net button after executing some asp code , you can register javascript and get executed .


string javaScript = " ( script language=' javascript' ) window.close( ) (/script) "; Page.RegisterStartupScript("myScript", javaScript);

This will close the window where this code will be executed.

Thursday, November 6, 2008

Javascript data types

1.Number
2.String
3.Boolean
4.Function
5.Object
6.Null
7.Undefined

Wednesday, November 5, 2008

isNaN

Return true if the argument is not a number

Monday, October 27, 2008

To Check if an input contains any afphabetic values

function HasAlpha(Txt)
{
strLen = Txt.length;

for(i=0; i < strLen;i++)
{
if((Txt.charAt(i)<"0") || (Txt.charAt(i)>"9"))
{
return true;
}
}
return false;


}

Saturday, September 13, 2008

Convert letters to Uppercase

Make on css class definition in your css file if it is or create new and assign CssClass property to the class you make. As shown below.

.ToUpperCase
{
text-transform: uppercase;
}



TextBox1.CssClass=ToUpperCase;

Wednesday, August 20, 2008

Accept Only Numbers In Text Box

//This javascript can be used to accept only numbers in any text box in asp.net





//After Adding this script to souce code please add the following statement on pageLoad event to register the java script to text box named txtRs



txtRs.Attributes.Add(”onkeydown”, “JavaScript:return isNumericKeyPressed();”);