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. Problem Of Getting Image ID Through Javascript

Problem Of Getting Image ID Through Javascript

Scheduled Pinned Locked Moved ASP.NET
helpjavascript
2 Posts 2 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.
  • V Offline
    V Offline
    vishnukamath
    wrote on last edited by
    #1

    Hi, I have a Imagebutton In a ContentplaceHolder Where I have to Adjust the height and width of the imagebutton with the scrren resolution. for that i had written a javascript.. ======================================================== if ((screen.width>1024) && (screen.height>768)) { var theImg = document.getElementById('Image1'); theImg.width = "100px"; theImg.height = "100px"; } else { var Img = document.getElementById('ctl00_ContentPlaceHolder1_Image1'); Img.width = "50px"; Img.height = "50px"; } =============================================== in the above code 'Image1' is the id of imagebutton.. im getting null value error when im using the above javascript. i have also used 'ct100_contentplaceholder_Image1' and '<%image1.ClientID%>' But both of are not worked. So Please suggest a solution for this problem. thanks in advance, vishnu

    G 1 Reply Last reply
    0
    • V vishnukamath

      Hi, I have a Imagebutton In a ContentplaceHolder Where I have to Adjust the height and width of the imagebutton with the scrren resolution. for that i had written a javascript.. ======================================================== if ((screen.width>1024) && (screen.height>768)) { var theImg = document.getElementById('Image1'); theImg.width = "100px"; theImg.height = "100px"; } else { var Img = document.getElementById('ctl00_ContentPlaceHolder1_Image1'); Img.width = "50px"; Img.height = "50px"; } =============================================== in the above code 'Image1' is the id of imagebutton.. im getting null value error when im using the above javascript. i have also used 'ct100_contentplaceholder_Image1' and '<%image1.ClientID%>' But both of are not worked. So Please suggest a solution for this problem. thanks in advance, vishnu

      G Offline
      G Offline
      GlobX
      wrote on last edited by
      #2

      Definitely use the ClientID property, because the generated ID could change down the track. Also, try:

      if ((screen.width>1024) && (screen.height>768))
      {
      var theImg = document.getElementById('<%image1.ClientID%>');

      theImg.**style**.width = "100px";
      theImg.**style**.height = "100px";
      

      }
      else
      {
      var Img = document.getElementById('<%image1.ClientID%>');

      Img.**style**.width = "50px";
      Img.**style**.height = "50px";
      

      }

      I believe the width and height properties are a Unit or something similar - the width and height of the style will allow you to enter the CSS-like values (i.e. "100px"). Let me know how you go :) P.S. Also check the source of the web page when you view it to ensure that '<%image1.ClientID%>' is actually being replaced with the ClientID.

      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