Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi EveryOne,

I'm validating some textboxes on click of a button using Jquery, But the JQuery is not finding the elements by ID. If i find with class name then it finds. What is the problem here?. I'm using Master page , is anything wrong with the master page..? Even the button also not finding .


Master Page :

XML
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="AdminMaster.master.cs"
    Inherits="Admin_AdminMaster" %>

<!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 src="../Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <link href="../Styles/MasterCMS.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td colspan="2">
                    <img src="../Images/AssetManagement_ver1_transparent_bg_jpg.jpg" alt="" />
                </td>
            </tr>
            <tr>
                <td>
                    <ul>
                        <li><a href="Summary.aspx">Summary</a></li>
                        <li><a href="UserRegistration.aspx">Registration</a></li>
                        <li><a href="Clients.aspx">Clients</a></li>
                        <li><a href="DocumentsUpload.aspx">Documents Uplaod</a></li>
                    </ul>
                </td>
                <td>
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                    </asp:ContentPlaceHolder>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>


<pre lang="c#">



and Content Page is


XML
<asp:Content ContentPlaceHolderID="head" runat="server">
    <%--<script src="../Scripts/Validations.js" type="text/javascript"></script>--%>

    <script type="text/javascript">

        $(this).ready(function () {

            
            $("#btnRegister).click(function () {
                if ($('#txtuserid').val().length == 0) {
                    alert('Enter Userid');
                    return false;
                }
            });

        });
    </script>
</asp:Content>
<asp:Content runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
    <table>
        <tr>
            <td>
                <b>Client Registration</b>
            </td>
        </tr>
        <tr>
            <td>
                User ID <span>*</span>
            </td>
            <td>
                <asp:TextBox runat="server" ID="txtUserID" CssClass="txt10"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Password <span>*</span>
            </td>
            <td>
                <asp:TextBox runat="server" ID="txtPassword"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                User Name <span>*</span>
            </td>
            <td>
                <asp:TextBox runat="server" ID="txtUsername"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Email ID <span>*</span>
            </td>
            <td>
                <asp:TextBox runat="server" ID="txtEmail"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Contact <span>*</span>
            </td>
            <td>
                <asp:TextBox runat="server" ID="txtContact"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Company <span>*</span>
            </td>
            <td>
                <asp:TextBox runat="server" ID="txtCompany"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Designation
            </td>
            <td>
                <asp:TextBox runat="server" ID="txtDesignation"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Select Region
            </td>
            <td>
                <asp:DropDownList runat="server" ID="ddlRegion">
                    <asp:ListItem Value="0" Selected="True">USOR</asp:ListItem>
                    <asp:ListItem Value="1">NUSOR</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center" style="color: Red;">
                <asp:Label runat="server" ID="lblError"></asp:Label>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <asp:Button runat="server" ID="btnRegister" Text="Register" CssClass="btnClass" OnClick="btnRegister_Click" />
            </td>
        </tr>
    </table>
</asp:Content>


its urgent..
Posted
Updated 15-Jul-13 19:15pm
v5
Comments
Thanks7872 15-Jul-13 23:58pm    
Always post code with this type of specific issues.No one can assume what you have done so far.
Sergey Alexandrovich Kryukov 16-Jul-13 0:07am    
Your logic itself is already incorrect. Even if some class name is the same as the argument of document.getElementById and if the element with this class is found, it does not mean that "Jquery dont find elements by ID but finds by class". Rather, it find it by id which happens to be the same as some class. (Or this fragment of code is not executed at all, or anything else...)

Relevant code sample could help.
—SA
Rockstar_ 16-Jul-13 0:10am    
please check once my updated questions and code..
Rockstar_ 16-Jul-13 0:10am    
I'm finding by ID
Thanks7872 16-Jul-13 0:19am    
Well your aim is to verify that no field should be left blank,right? Why dont you make use of requiredfield validator?

1 solution

you must access any id of asp.net controls using clientId, as those ID will get resolved to something else. so instead of
JavaScript
$("#btnRegister").click
try
C#
$('#<%= btnRegister.ClientID %>').click()
 
Share this answer
 
v2
Comments
Rockstar_ 17-Jul-13 0:28am    
Thanks, it worked..

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