How to hide asp image control using java script
. I tried following code but its not working. image is not visible when on change function is called.
javascript is at client side if I set visibility property of image control to false then can i make it visible through javascript?
What I have tried:
image control code:
javascript:
function previewFile() {
var preview = document.querySelector(''#'');
var file = document.querySelector(''#'').files[0];
document.getElementById("Image4").style.visibility = "visible"
var reader = new FileReader();
reader.onloadend = function () {
preview.src = reader.result;
}
if (file) {
reader.readAsDataURL(file);
} else {
preview.src = "";
}
}
解决方案
If you try to hide the Image asImage1.Visible = true;
in the server, the Image element will be completely removed from the DOM[^]. and you wont be able to control the visibility in javascript( client side).
try this, in c# to hide the element
Image1.Style.Add("display","none");
now the visibility functionality will work as mentioned in the Solution 1
Note: display:none removes the element from the place, allowing other elements to fill in that place where as
visibility:hidden leaves the element in the declared place of the page such that it will still occupies the space
HTML DOM Style visibility Property[^] where element will still occupy space when invisible
document.getElementById("Image4").style.visibility = "visible";
document.getElementById("Image4").style.visibility = "hidden";
HTML DOM Style display Property[^] where element will not occupy space when hidden
document.getElementById("Image4").style.display = "block";
document.getElementById("Image4").style.display = "none";