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