tags:

views:

15

answers:

2

How do i hide an html img from a code behind file in VB.NET? The img tag doesnt have a runat attribute and hence not a server control. I tried

Dim cs As ClientScriptManager = Page.ClientScript
cs.RegisterStartupScript(Me.GetType(), "alert", "alert('test')")

in the Page_Load(). But doest work. I want to access the id using javascript (document.getElementbyId('idofimg').style.visibility = 'hidden')

A: 

You could add the img tag to a panel control which would render as a div. You could still access the image in javascript when it is on the page, but then you could also hide the panel in the code behind.

---Update

Instead of rendering as:

<img sr="whatever.png" alt="Whatever" />

It would render similar to:

<div id="aspServerIdName"><img sr="whatever.png" alt="Whatever" /></div>

Looking at your issue more, you will probably just want to use an ASP.NET Image control and set it's ClientIdMode attribute to static so that you can access it in javascript by ID.

wllmsaccnt
will it render the img in the same way after adding a panel control?
Abhi
added the img tag inside a Panel server control and then set it's Visible property to false in the Page_Load(). Thank you.
Abhi
A: 

How about wrapping your image in a span or div tag with the display='none' or visibility='hidden' style attribute?

enforge
I want to change the attributes by calling javascript code 'in-line'. Something like - ...RegisterStartupScript(Me.GetType(), 'test', 'document.getElementById('id').style.visibility='hidden'')
Abhi