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. javascipt document.getElementByID() problem using MasterPage

javascipt document.getElementByID() problem using MasterPage

Scheduled Pinned Locked Moved ASP.NET
javascripttoolshelptutorial
4 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
    sivaprakas
    wrote on last edited by
    #1

    hai i new to using masterpage when i use this code any of page in my website javascript code appears how to overcome this problem very urgent <script language=javascript>function test() { alert(document.getElementById("editName").value)); } </script> but without using masterpage this code working perfectly

    V 1 Reply Last reply
    0
    • S sivaprakas

      hai i new to using masterpage when i use this code any of page in my website javascript code appears how to overcome this problem very urgent <script language=javascript>function test() { alert(document.getElementById("editName").value)); } </script> but without using masterpage this code working perfectly

      V Offline
      V Offline
      Venkatesh Mookkan
      wrote on last edited by
      #2

      sivaprakas wrote:

      function test() { alert(document.getElementById("editName").value)); }

      This would work with normal pages. But in MasterPages, it is different. Even though you have given the ID as "editname" ASP.NET appends a prefix of the contentplaceholder name along with the actual name. To overcome this, you can set the JavaScript call at runtime from the CodeBehind using editname.ClientID property as parameter to the JS function rather than hardcoding it.

      [Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot

      S 1 Reply Last reply
      0
      • V Venkatesh Mookkan

        sivaprakas wrote:

        function test() { alert(document.getElementById("editName").value)); }

        This would work with normal pages. But in MasterPages, it is different. Even though you have given the ID as "editname" ASP.NET appends a prefix of the contentplaceholder name along with the actual name. To overcome this, you can set the JavaScript call at runtime from the CodeBehind using editname.ClientID property as parameter to the JS function rather than hardcoding it.

        [Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot

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

        Hi thanks for all reply i use "ctl00$ContentPlaceHolder1$editName" as ID and comeout from the pbm

        N 1 Reply Last reply
        0
        • S sivaprakas

          Hi thanks for all reply i use "ctl00$ContentPlaceHolder1$editName" as ID and comeout from the pbm

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

          sivaprakas wrote:

          "ctl00$ContentPlaceHolder1$editName" as ID and comeout from the pbm

          Hard coding this is a bad practice. Once you changes the content place holder name, your script will stop functioning. You should use ClientId which is the correct solution.

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

          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