Friday, 8 April 2011

Include Javascripts from JS File to Aspx Page

1) Add Javascript file

function manageFocus(e,objFocusOn)
{
    try
    {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
        {
            if(objFocusOn != null)
            {
                objFocusOn.focus();
                objFocusOn.select();
            }
             return false;
        }
        else
        {
            return true;
        }
   
    }catch(error)
    {
        var showerror="There was an error on this page.\n\n";
        showerror+="Error : " + error.description + "\n\n";
        showerror+="Error description: " + error + "\n\n";
        showerror+="Click OK to continue.\n\n";
        alert(showerror);
    }
}

2) Add reference of JS file in APSX page as
<script type="text/javascript" src="Scripts/Sales.js" language="javascript"></script>

3) Call the functions of JS file we can call in ASPX page or add the attributes of controls in .cs file of page
 txtRate.Attributes.Add("onkeyup", "javascript:manageFocus(event," + txtEnteredQty.ClientID + ");");

No comments:

Post a Comment