By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,537 Members | 1,750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,537 IT Pros & Developers. It's quick & easy.

Trying to hide an img control upon command

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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" <dn******@dtgnet.comwrote in message
news:41**********************************@m73g2000 hsh.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

P: n/a
On Apr 24, 11:10*am, "Madhur" <s...@df.comwrote:
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.comwrote in message

news:41**********************************@m73g2000 hsh.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.- 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;
}
Jun 27 '08 #3

P: n/a
Can you paste the full code ?

--
MAdhur

"Doogie" <dn******@dtgnet.comwrote in message
news:64**********************************@l64g2000 hse.googlegroups.com...
On Apr 24, 11:10 am, "Madhur" <s...@df.comwrote:
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.comwrote in message

news:41**********************************@m73g2000 hsh.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.- 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;
}

Jun 27 '08 #4

P: n/a
On Apr 24, 11:27*pm, "Madhur" <s...@df.comwrote:
Can you paste the full code ?

--
MAdhur

"Doogie" <dnlwh...@dtgnet.comwrote in message

news:64**********************************@l64g2000 hse.googlegroups.com...
On Apr 24, 11:10 am, "Madhur" <s...@df.comwrote:


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.comwrote in message
news:41**********************************@m73g2000 hsh.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.- 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;

}- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
I actually got it to work. A friend suggested adding runat="server"
to the <imgtag 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$MasterContentPlaceHol der$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$MasterContentPlaceHol der$txtFrom')"/>

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

Any ideas?
Jun 27 '08 #5

P: n/a

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 <imgtag 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$MasterContentPlaceHol der$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$MasterContentPlaceHol der$txtFrom')"/>

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

Any ideas?
Jun 27 '08 #6

P: n/a
On Apr 25, 9:27*am, "David"
<david.colliver.N...@revilloc.REMOVETHIS.comwrot e:
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 <imgtag 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$MasterContentPlaceHol der$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$MasterContentPlaceHol der$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.
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.