You must Sign In to post a response.
  • Category: JavaScript

    How to get the correct id instead of ids like this -----> ctl00$cphMain$txtListname

    hi friend

    i wrote the javascript and called it but actually my textbox name which i am passing as parrameter is (txtListname) but it is not identifying this actual id and it is telling that (*ctl00$cphMain$txtListname) this is the id so how to make my id to be used

    content page***************

    <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" OnClientClick="return Validate(ctl00$cphMain$txtListname)"
    Text="Submit" TabIndex="15" />

    javascript*******************


    <script type="text/javascript">
    function Validate(ctl00$cphMain$txtListname)
    {
    if (ctl00$cphMain$txtListname.value == "") {

    alert("you must enter the List name");
    return false;

    }


    }
  • #641001
    Hi malar.

    you can try like this ....

    Sample Code:

    <asp:TextBox ID="txt" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" OnClientClick="return val(this.form.txt);" runat="server" Text="Button" />


    <script type="text/javascript">
    function val(id)
    {
    alert(id.id);
    }
    </script>

    from this you can get id.....

  • #641002
    do like below code :

    <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" OnClientClick='return Validate(<%=txtListname.ClientID %>)'
    Text="Submit" TabIndex="15" />

    If it helps you then Rate this.

    Best Regards,
    Manoranjan Sahoo
    http://www.dotnetsquare.com
    Blog: http://blog.msahoo.net

  • #641004
    hi harinarayanan

    thanks for the reply but the result told me when i put alert(id.id) it says id is null...

    hi manoranjanshahoo

    thanks for the reply i tried your method but it did not work


    so anyone can help me plz.........

  • #641069
    sorry some typing mistake.
    try below :

    <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" OnClientClick='return Validate("<%=txtListname.ClientID %>")'
    Text="Submit" TabIndex="15" />

    then

    <script type="text/javascript">
    function Validate(txtbx)
    {
    var txtobj=document.getElementById(txtbx);
    if (txtobj.value == "") {
    alert("you must enter the List name");
    return false;
    }
    }
    </script>

    If it helps you then Rate this.

    Best Regards,
    Manoranjan Sahoo
    http://www.dotnetsquare.com
    Blog: http://blog.msahoo.net

  • #641081
    Please change the method like this.


    <script type="text/javascript">
    function Validate(ctl00_cphMain_txtListname)
    {
    if (ctl00_cphMain_txtListname.value == '')
    {

    alert("you must enter the List name");
    return false;

    }



    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #641176
    sorry friends

    thanks for all your reply but still did not get any solution to my javascript


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.