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
csharpjavascriptdotnetsysadmintools
6 Posts 4 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.
  • L Offline
    L Offline
    Lex Luthor
    wrote on last edited by
    #1

    Hello, Have anyone used javascript in an web user control(.ascx) (Visual Studion 2005, .NET Framework 2.0)? Alert works fine, but for example, I cant seem to get the ID of an asp checkbox. function CheckBoxChecked(id) { 1. alert(id); var elem = document.getElementById(id); var temp = document.getElementById('CheckBox1'); 2. alert(elem); 3. alert(temp); } results in: 1. Undefined 2. null 3. null I invoke the script as follows: asp:CheckBox ID="CheckBox1" runat="server" onclick="javascript:CheckBoxChecked()" (I have used javascripts with .ascx components before, though they were predifined by Telerik, which contols I were using at the time) //LL

    H M P L 4 Replies Last reply
    0
    • L Lex Luthor

      Hello, Have anyone used javascript in an web user control(.ascx) (Visual Studion 2005, .NET Framework 2.0)? Alert works fine, but for example, I cant seem to get the ID of an asp checkbox. function CheckBoxChecked(id) { 1. alert(id); var elem = document.getElementById(id); var temp = document.getElementById('CheckBox1'); 2. alert(elem); 3. alert(temp); } results in: 1. Undefined 2. null 3. null I invoke the script as follows: asp:CheckBox ID="CheckBox1" runat="server" onclick="javascript:CheckBoxChecked()" (I have used javascripts with .ascx components before, though they were predifined by Telerik, which contols I were using at the time) //LL

      H Offline
      H Offline
      hemant kaushal
      wrote on last edited by
      #2

      try asp:CheckBox ID="CheckBox1" runat="server" onclick="javascript:CheckBoxChecked(this)" function CheckBoxChecked(ctl) { alert(ctl.id) } :)

      1 Reply Last reply
      0
      • L Lex Luthor

        Hello, Have anyone used javascript in an web user control(.ascx) (Visual Studion 2005, .NET Framework 2.0)? Alert works fine, but for example, I cant seem to get the ID of an asp checkbox. function CheckBoxChecked(id) { 1. alert(id); var elem = document.getElementById(id); var temp = document.getElementById('CheckBox1'); 2. alert(elem); 3. alert(temp); } results in: 1. Undefined 2. null 3. null I invoke the script as follows: asp:CheckBox ID="CheckBox1" runat="server" onclick="javascript:CheckBoxChecked()" (I have used javascripts with .ascx components before, though they were predifined by Telerik, which contols I were using at the time) //LL

        M Offline
        M Offline
        minhpc_bk
        wrote on last edited by
        #3

        Hi there, Since the checkbox control is placed in a user control, so the ClientID of the control is not as simple as the "CheckBox1". You can view source the web page to have an idea on the real value of the id property of the control at the client side, you will find that it contains the web user control's id as the prefix.

        1 Reply Last reply
        0
        • L Lex Luthor

          Hello, Have anyone used javascript in an web user control(.ascx) (Visual Studion 2005, .NET Framework 2.0)? Alert works fine, but for example, I cant seem to get the ID of an asp checkbox. function CheckBoxChecked(id) { 1. alert(id); var elem = document.getElementById(id); var temp = document.getElementById('CheckBox1'); 2. alert(elem); 3. alert(temp); } results in: 1. Undefined 2. null 3. null I invoke the script as follows: asp:CheckBox ID="CheckBox1" runat="server" onclick="javascript:CheckBoxChecked()" (I have used javascripts with .ascx components before, though they were predifined by Telerik, which contols I were using at the time) //LL

          P Offline
          P Offline
          Pankaj Kulkarni
          wrote on last edited by
          #4

          Hi there,

          Lex Luthor wrote:

          asp:CheckBox ID="CheckBox1" runat="server" onclick="javascriptCheckBoxChecked()"

          I think you have missed the colon ":" and control in above line i.e. you should write asp:CheckBox ID="CheckBox1" runat="server" onclick="javascript:CheckBoxChecked(this)" Pankaj Kulkarni

          1 Reply Last reply
          0
          • L Lex Luthor

            Hello, Have anyone used javascript in an web user control(.ascx) (Visual Studion 2005, .NET Framework 2.0)? Alert works fine, but for example, I cant seem to get the ID of an asp checkbox. function CheckBoxChecked(id) { 1. alert(id); var elem = document.getElementById(id); var temp = document.getElementById('CheckBox1'); 2. alert(elem); 3. alert(temp); } results in: 1. Undefined 2. null 3. null I invoke the script as follows: asp:CheckBox ID="CheckBox1" runat="server" onclick="javascript:CheckBoxChecked()" (I have used javascripts with .ascx components before, though they were predifined by Telerik, which contols I were using at the time) //LL

            L Offline
            L Offline
            Lex Luthor
            wrote on last edited by
            #5

            As one of the answers (minhpc_bk) also implied I had to go through the .aspx which uses the control to get the information I required. I use this function each time I wan't an id or so for one of the controls on the .ascx. function GetIdString() { var id = new String("<%= this.ClientID %>_"); return id; } Now I can easily do something like this in another function: document.getElementById(GetIdString()+"CheckBox1") Thanx everybody for the response... //LL

            P 1 Reply Last reply
            0
            • L Lex Luthor

              As one of the answers (minhpc_bk) also implied I had to go through the .aspx which uses the control to get the information I required. I use this function each time I wan't an id or so for one of the controls on the .ascx. function GetIdString() { var id = new String("<%= this.ClientID %>_"); return id; } Now I can easily do something like this in another function: document.getElementById(GetIdString()+"CheckBox1") Thanx everybody for the response... //LL

              P Offline
              P Offline
              Pankaj Kulkarni
              wrote on last edited by
              #6

              Hi, It's really cool man. I also tried. Thanks minhpc_bk and Lex Luthor Pankaj Kulkarni

              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