Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<script type="text/javascript" src="script/JQuery.js"></script>

    <script type="text/javascript">
    $(function(){
    $('#<%=btnedit.ClientID %>').click(function(){

    var Isvalid=true;
    var filter = /^[1-9][0-9]*$/
    if($('#<%= tbxarea.ClientID %>').val()=='')
    {
        $('#<%= tbxarea.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
        Isvalid=false;
    }
    else
    {
        if(filter.test($('#<%= tbxarea.ClientID %>').val()))
        {
            $('#<%= tbxarea.ClientID %>').css({"border-color": "",
             "border-width":"",
             "border-style":""});
        }
        else
        {
            $('#<%= tbxarea.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
            Isvalid=false;
        }
    }

    if($('#<%= tbxmatte.ClientID %>').val()=='')
    {
        $('#<%= tbxmatte.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
        Isvalid=false;
    }
    else
    {
        if(filter.test($('#<%= tbxmatte.ClientID %>').val()))
        {
            $('#<%= tbxmatte.ClientID %>').css({"border-color": "",
             "border-width":"",
             "border-style":""});
        }
        else
        {
            $('#<%= tbxmatte.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
            Isvalid=false;
        }
    }
    if($('#<%= tbxglossy.ClientID %>').val()=='')
    {
        $('#<%= tbxglossy.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
        Isvalid=false;
    }
    else
    {
        if(filter.test($('#<%= tbxglossy.ClientID %>').val()))
        {
            $('#<%= tbxglossy.ClientID %>').css({"border-color": "",
             "border-width":"",
             "border-style":""});
        }
        else
        {
            $('#<%= tbxglossy.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
            Isvalid=false;
        }
    }
    if($('#<%= tbxtextured.ClientID %>').val()=='')
    {
        $('#<%= tbxtextured.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
        Isvalid=false;
    }
    else
    {
        if(filter.test($('#<%= tbxtextured.ClientID %>').val()))
        {
            $('#<%= tbxtextured.ClientID %>').css({"border-color": "",
             "border-width":"",
             "border-style":""});
        }
        else
        {
            $('#<%= tbxtextured.ClientID %>').css({"border-color": "red",
             "border-width":"1px",
             "border-style":"solid"});
            Isvalid=false;
        }
    }
    return Isvalid;
    });

    });
    </script>

---------------------------------------------------

Above is a jQuery function written in aspx page , how to implement the same in external js file
Posted

XML
Below is the sample code of one of the way through which you can resolve this problem. In this approach you need declare variables in JavaScript for holding server control id and then you need to use these variables inside your external JS file for attaching event.
Please let me know if you need any clarification.

ASPX page Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
<script>
var tbxareaId = '<%=tbxarea.ClientID%>';

</script>

    <script src="JavaScript/jquery-1.6.1.min.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="tbxarea" runat="server"></asp:TextBox>
    </div>
    </form>

    <script src="JavaScript/JScript1.js" type="text/javascript"></script>
</body>

</html>

External Javascript JScript1.js Code

$('#' + tbxareaId).bind('click', function() {
alert('User clicked on "foo."');
});
 
Share this answer
 
Comments
anbujeremiah 22-May-13 1:34am    
Hi mahesh bailwal

i am getting,


ReferenceError: $ is not defined
Source File: http://localhost:2682/ACC.WEB/script/Blank.js
Line: 2
XML
That error can only be caused by one of below things:

    1.Your JavaScript file is not being properly loaded into your page
    2.You have JavaScript running before the page is fully loaded, and as such, before jQuery is fully loaded.

Please make sure you include Jquery js file before using Jquery function, means first include file in your page header should be Jquery JS

<head runat="server">
    <script src="JavaScript/jquery-1.6.1.min.js" type="text/javascript"></script>
</head>


Please share your code snippet if it does not reslove your problem
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900