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. How to use java script code in user control

How to use java script code in user control

Scheduled Pinned Locked Moved ASP.NET
javajavascriptsysadmintoolshelp
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.
  • S Offline
    S Offline
    Sutheesh
    wrote on last edited by
    #1

    Hi, i created one user control, in that control i called function. But it is not working when i used that user control in my form. But the same coding can be working in pages. Can any one help me? In my user control i created one table like this,

    I write the code in server side as follows, HtmlTableRow htr,htr1; HtmlTableCell htc; htr = new HtmlTableRow(); htc = new HtmlTableCell(); htc.InnerHtml = "Sutheesh Visible"; htr.Cells.Add(htc); SampForum.Controls.Add(htr); htr1 = new HtmlTableRow(); htr1.ID = "Hello"; htc = new HtmlTableCell(); htc.InnerHtml = "Sutheesh Invisible"; htr1.Cells.Add(htc); htr1.Style.Add("display", "none"); htr.Attributes.Add("onClick", "ShowHide('" + htr1.ClientID+ "')"); Ftable.Controls.Add(htr1); JavaScript: function ShowHide(cell) { alert(cell); if(document.getElementById(cell).style.display=="none") document.getElementById(cell).style.display="inline"; else document.getElementById(cell).style.display="none"; }

    P 1 Reply Last reply
    0
    • S Sutheesh

      Hi, i created one user control, in that control i called function. But it is not working when i used that user control in my form. But the same coding can be working in pages. Can any one help me? In my user control i created one table like this,

      I write the code in server side as follows, HtmlTableRow htr,htr1; HtmlTableCell htc; htr = new HtmlTableRow(); htc = new HtmlTableCell(); htc.InnerHtml = "Sutheesh Visible"; htr.Cells.Add(htc); SampForum.Controls.Add(htr); htr1 = new HtmlTableRow(); htr1.ID = "Hello"; htc = new HtmlTableCell(); htc.InnerHtml = "Sutheesh Invisible"; htr1.Cells.Add(htc); htr1.Style.Add("display", "none"); htr.Attributes.Add("onClick", "ShowHide('" + htr1.ClientID+ "')"); Ftable.Controls.Add(htr1); JavaScript: function ShowHide(cell) { alert(cell); if(document.getElementById(cell).style.display=="none") document.getElementById(cell).style.display="inline"; else document.getElementById(cell).style.display="none"; }

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      Why isn't it working? You haven't stated what the problem is.

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      S 1 Reply Last reply
      0
      • P pmarfleet

        Why isn't it working? You haven't stated what the problem is.

        Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

        S Offline
        S Offline
        Sutheesh
        wrote on last edited by
        #3

        Thanks for ur reply friend. The page cannt find document.getElementById(cell), because it (cell) is created in usercontrol.

        N 1 Reply Last reply
        0
        • S Sutheesh

          Thanks for ur reply friend. The page cannt find document.getElementById(cell), because it (cell) is created in usercontrol.

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          Member 4755319 wrote:

          because it (cell) is created in usercontrol.

          Have you checked the page source ? Verify the alert is giving the same name which is there in the page source.

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

          S 1 Reply Last reply
          0
          • N N a v a n e e t h

            Member 4755319 wrote:

            because it (cell) is created in usercontrol.

            Have you checked the page source ? Verify the alert is giving the same name which is there in the page source.

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

            S Offline
            S Offline
            Sutheesh
            wrote on last edited by
            #5

            Thanks Navaneeth, Finally i got the answer by ur clue, i saw the page source it was different from the id. It includes usercontrolname_id. Now my user control is working fine.... Thanks alot..

            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