470,849 Members | 1,059 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Hiding images in a web app

Hi I have an img control I am trying to hide upon certain types of
commands in my code behind. When to hide it is directly tied to a
asp:dropdownlist control. So depending on what the user selects in
that dropdownlist, this image will be hidden or be displayed.

I have tied the onselectedindexchanged value of the dropdownlist to a
c-sharp method (not javascript) because other things are being done
as
well that I want to do server side. However, the img control is not
server side, I can't grab it on the c-sharp method.
So I tried to right something like this to do that
string myScript = "<script type='text/javascript'if (imgTo != null)
{ imgTo.width = 0; }</script>";
ClientScript.RegisterClientScriptBlock(this.GetTyp e(), "ABC",
myScript);
However, it keeps saying imgTo is undefined. Even if I modify my
script above to read if (imgTo != 'undefined') it still gives me the
same error. But it's not undefined, below is my HTML for it.
<img alt="To Calendar" id="imgTo" src="../Images/calendar.gif"
style="width:0" onclick="CallCalendar('ctl00$MasterContentPlaceHol der
$txtTo')"/>
Is there something else I could be missing?
I have tried to use a server side image control instead of the client
side one, but once I do that, for some reason, it keeps losing the
data in my CallCalendar method (see above) that is called in the
onclick method for imgTo because it is posting back. That
CallCalendar method popups up a calendar and assigns the value
selected to a text box on the form. I have tried to put a break
point
in my page load method to see why I lose the value in the text box,
but by the time it gets to page load the value in the text box is
already gone (although I can see it show up on the screen). So I'm
thinking the client side image is my best way, if I can just figure
out how to get it to realize imgTo is really thee.
Jun 27 '08 #1
1 887
The fastest way (server-side) is to put what you want to show and hide into
a Panel and then use the SelectedIndexChanged event of the DropDownList to
manage the properties of the Panel; which renders as a div at runtime. If
you want to learn to do this with Javascript send me two hundred dollars ;-)

"Doug" <dn******@dtgnet.comwrote in message
news:a8**********************************@59g2000h sb.googlegroups.com...
Hi I have an img control I am trying to hide upon certain types of
commands in my code behind. When to hide it is directly tied to a
asp:dropdownlist control. So depending on what the user selects in
that dropdownlist, this image will be hidden or be displayed.

I have tied the onselectedindexchanged value of the dropdownlist to a
c-sharp method (not javascript) because other things are being done
as
well that I want to do server side. However, the img control is not
server side, I can't grab it on the c-sharp method.
So I tried to right something like this to do that
string myScript = "<script type='text/javascript'if (imgTo != null)
{ imgTo.width = 0; }</script>";
ClientScript.RegisterClientScriptBlock(this.GetTyp e(), "ABC",
myScript);
However, it keeps saying imgTo is undefined. Even if I modify my
script above to read if (imgTo != 'undefined') it still gives me the
same error. But it's not undefined, below is my HTML for it.
<img alt="To Calendar" id="imgTo" src="../Images/calendar.gif"
style="width:0" onclick="CallCalendar('ctl00$MasterContentPlaceHol der
$txtTo')"/>
Is there something else I could be missing?
I have tried to use a server side image control instead of the client
side one, but once I do that, for some reason, it keeps losing the
data in my CallCalendar method (see above) that is called in the
onclick method for imgTo because it is posting back. That
CallCalendar method popups up a calendar and assigns the value
selected to a text box on the form. I have tried to put a break
point
in my page load method to see why I lose the value in the text box,
but by the time it gets to page load the value in the text box is
already gone (although I can see it show up on the screen). So I'm
thinking the client side image is my best way, if I can just figure
out how to get it to realize imgTo is really thee.

Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Steve Loft | last post: by
6 posts views Thread by R. Rajesh Jeba Anbiah | last post: by
8 posts views Thread by Fabian | last post: by
10 posts views Thread by mark | r | last post: by
2 posts views Thread by coolwarrior | last post: by
4 posts views Thread by web_design | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.