Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. JavaScript in Web User Control

JavaScript in Web User Control

Scheduled Pinned Locked Moved ASP.NET
helpjavascriptsysadmin
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    Usharva
    wrote on last edited by
    #1

    Hi!! I am using Javascript in user control.. My problem is i am not getting the value of textbox in javascript. here is my code function InputChange() { var ctl=document.getElementById('txtEmp').value; alert(ctl); } <asp:TextBox ID="txtEmp" onchange="InputChange();" runat="server" CssClass="form_textbox" Width ="80px"></asp:TextBox> its displaying 'ctl' value as 'null' please help me ASAP... Thanks in Advance...

    S R 3 Replies Last reply
    0
    • U Usharva

      Hi!! I am using Javascript in user control.. My problem is i am not getting the value of textbox in javascript. here is my code function InputChange() { var ctl=document.getElementById('txtEmp').value; alert(ctl); } <asp:TextBox ID="txtEmp" onchange="InputChange();" runat="server" CssClass="form_textbox" Width ="80px"></asp:TextBox> its displaying 'ctl' value as 'null' please help me ASAP... Thanks in Advance...

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      Its because when you are using User Control or anything ASP genrate a unique client id to every control you are giving wrong i Id i guess unction InputChange() { var ctl=document.getElementById("<%=txtEmp.ClientID %>").value; alert(ctl); }

      Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

      modified on Tuesday, April 22, 2008 3:41 AM

      U 1 Reply Last reply
      0
      • U Usharva

        Hi!! I am using Javascript in user control.. My problem is i am not getting the value of textbox in javascript. here is my code function InputChange() { var ctl=document.getElementById('txtEmp').value; alert(ctl); } <asp:TextBox ID="txtEmp" onchange="InputChange();" runat="server" CssClass="form_textbox" Width ="80px"></asp:TextBox> its displaying 'ctl' value as 'null' please help me ASAP... Thanks in Advance...

        R Offline
        R Offline
        R Giskard Reventlov
        wrote on last edited by
        #3

        Most likely the id of the control on the emitted page is actually something like: ctl00_master_txtEmp or similar. Look at the source to find this: it is named after the parent element (such as the ContentPlaceHolderID). As an example right click this page, click view source and you will see many examples of this. Your code would then be: var ctl=document.getElementById('ctl00_master_txtEmp').value; alert(ctl);

        me, me, me

        1 Reply Last reply
        0
        • U Usharva

          Hi!! I am using Javascript in user control.. My problem is i am not getting the value of textbox in javascript. here is my code function InputChange() { var ctl=document.getElementById('txtEmp').value; alert(ctl); } <asp:TextBox ID="txtEmp" onchange="InputChange();" runat="server" CssClass="form_textbox" Width ="80px"></asp:TextBox> its displaying 'ctl' value as 'null' please help me ASAP... Thanks in Advance...

          S Offline
          S Offline
          Sandeep Akhare
          wrote on last edited by
          #4

          Its better to give a client id dynamic instead of static Check my above modified code that will work

          Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

          1 Reply Last reply
          0
          • S Sandeep Akhare

            Its because when you are using User Control or anything ASP genrate a unique client id to every control you are giving wrong i Id i guess unction InputChange() { var ctl=document.getElementById("<%=txtEmp.ClientID %>").value; alert(ctl); }

            Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

            modified on Tuesday, April 22, 2008 3:41 AM

            U Offline
            U Offline
            Usharva
            wrote on last edited by
            #5

            Thanks a lot sandeep... its working.... thank u very much....

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups