Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trying to hide an img control upon command

1 view
Skip to first unread message

Doogie

unread,
Apr 24, 2008, 11:18:19 AM4/24/08
to
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.GetType(), "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$MasterContentPlaceHolder
$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.

Madhur

unread,
Apr 24, 2008, 12:10:49 PM4/24/08
to
I don't think you can refer the specified element directly using string id.

You will need to obtain DOM element by using
var obj =getdocumentelementbyid('imtTo')

and then perform the operations on it.

Hope this helps.

--
Madhur

"Doogie" <dnlw...@dtgnet.com> wrote in message
news:41068cdc-442c-4135...@m73g2000hsh.googlegroups.com...

Doogie

unread,
Apr 24, 2008, 12:32:29 PM4/24/08
to
On Apr 24, 11:10 am, "Madhur" <s...@df.com> wrote:
> I don't think you can refer the specified element directly using string id.
>
> You will need to obtain DOM element by using
> var obj =getdocumentelementbyid('imtTo')
>
> and then perform the operations on it.
>
> Hope this helps.
>
> --
> Madhur
>
> "Doogie" <dnlwh...@dtgnet.com> wrote in message
> > out how to get it to realize imgTo is really thee.- Hide quoted text -
>
> - Show quoted text -

I tried doing it this way (both with the way you had the case on
getdocumentelementbyid and the way I have it below). Neither one
worked. I get an "object expected error" now:

var a = getDocumentElementByID('imgTo');
if (a != null)
{
a.width = 0;
}

Madhur

unread,
Apr 25, 2008, 12:27:20 AM4/25/08
to
Can you paste the full code ?

--
MAdhur

"Doogie" <dnlw...@dtgnet.com> wrote in message

news:647fcdec-2242-4bd6...@l64g2000hse.googlegroups.com...

Doogie

unread,
Apr 25, 2008, 9:55:22 AM4/25/08
to
On Apr 24, 11:27 pm, "Madhur" <s...@df.com> wrote:
> Can you paste the full code ?
>
> --
> MAdhur
>
> - Show quoted text -- Hide quoted text -

>
> - Show quoted text -

I actually got it to work. A friend suggested adding runat="server"
to the <img> tag and that works great. However, now something else is
weird...if I have my tag set up like this:

<img alt="From Calendar" runat="server" id="imgFrom" src="../Images/
calendar.gif" style="width:15"
onclick="CallCalendar('ctl00$MasterContentPlaceHolder$txtFrom')"/>

and I run this line of code in the code-behind:

imgFrom.Width = 15 --to make it visible.

or

imgFrom.Width = 0 ---to hide it.

This works great. But when the width is set to 0, I can still see a
very small dot on the screen. Not a big deal but worth trying to
improve. So I switched my code to this to make it invisible

imgFrom.Width = -1 ---to hide it.

Now the image never hides. The exact same thing occurs when I do this
to my tag (setting initial image width value to -1):

<img alt="From Calendar" runat="server" id="imgFrom" src="../Images/
calendar.gif" style="width:-1"
onclick="CallCalendar('ctl00$MasterContentPlaceHolder$txtFrom')"/>

if I run the code imgFrom.Width = -1 it still doesn't hide.

Any ideas?

David

unread,
Apr 25, 2008, 10:27:02 AM4/25/08
to

use...

imgFrom.Visible = false


--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

Doogie

unread,
Apr 25, 2008, 10:50:51 AM4/25/08
to
On Apr 25, 9:27 am, "David"

<david.colliver.N...@revilloc.REMOVETHIS.com> wrote:
> use...
>
> imgFrom.Visible = false
>
> --
> Best regards,
> Dave Colliver.http://www.AshfieldFOCUS.com
> ~~http://www.FOCUSPortals.com- Local franchises available

>
> I actually got it to work.  A friend suggested adding runat="server"
> to the <img> tag and that works great.  However, now something else is
> weird...if I have my tag set up like this:
>
> <img alt="From Calendar" runat="server" id="imgFrom" src="../Images/
> calendar.gif" style="width:15"
> onclick="CallCalendar('ctl00$MasterContentPlaceHolder$txtFrom')"/>
>
> and I run this line of code in the code-behind:
>
> imgFrom.Width = 15  --to make it visible.
>
> or
>
> imgFrom.Width = 0 ---to hide it.
>
> This works great.  But when the width is set to 0, I can still see a
> very small dot on the screen.  Not a big deal but worth trying to
> improve.  So I switched my code to this to make it invisible
>
> imgFrom.Width = -1 ---to hide it.
>
> Now the image never hides.  The exact same thing occurs when I do this
> to my tag (setting initial image width value to -1):
>
> <img alt="From Calendar" runat="server" id="imgFrom" src="../Images/
> calendar.gif" style="width:-1"
> onclick="CallCalendar('ctl00$MasterContentPlaceHolder$txtFrom')"/>
>
> if I run the code imgFrom.Width = -1 it still doesn't hide.
>
> Any ideas?

Ok, I apologize for my silliness. I swear yesterday when I was trying
to use this img tag and get it accessible from the server, Visible
wasn't a property there. Now it is. Boy oh boy.

0 new messages