May 11, 2011

How to find the Parent page controls in child page using javascript [ window.opener....]

<html>
<head>
<script type="text/javascript">
function openWin()
{
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("This is 'myWindow'!");
myWindow.focus();
myWindow.opener.document.write("<p>This is the source window!</p>");
}
</script>
</head>
<body>

<input type="button" value="Open 'myWindow'" onclick="openWin()" />

</body>
</html>

Checking ComboBox with Javascript

function IsComboEmpty(ddlObj)
{
    if (document.getElementById(txtObj).selectedIndex == '0') {
            return false;
        }
    return true;
}

Email Validation in Javascript

function emailValidate(obj) {   
var reg = /^(?!\.)+([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3})$/;
    var address = document.getElementById(obj).value;
    if (reg.test(address) == false) {
        return false;
    }
    return true;
}

Apr 13, 2011

How to call Codebehind method from Javascript (C# ASP.NET)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CodeBehindMethodFromJavascript.aspx.cs"Inherits="CodeBehindMethodFromJavascript" %><!
<
<
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">html xmlns="http://www.w3.org/1999/xhtml">head runat="server"><title></title><script type="text/javascript">

alert(
}

</
<
function test() {var VarA = document.getElementById("txtAB").value;'<%=new CodeBehindMethodFromJavascript().GetName("' + VarA + '")%>');</script>head>body><form id="form1" runat="server"><div><input type="text" id="txtAB" /><input type="button" value="ClickMe" onclick="test()" /></div>
</
</
</form>body>html>

Regards

Regards