Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

Trying to hide an img control upon command

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Doogie - 24 Apr 2008 16:18 GMT
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 - 24 Apr 2008 17:10 GMT
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

> 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
[quoted text clipped - 34 lines]
> 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.
Doogie - 24 Apr 2008 17:32 GMT
> I don't think you can refer the specified element directly using string id.
>
[quoted text clipped - 48 lines]
>
> - 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 - 25 Apr 2008 05:27 GMT
Can you paste the full code ?

--
MAdhur

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.
[quoted text clipped - 53 lines]
>
> - 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;
}
Doogie - 25 Apr 2008 14:55 GMT
> Can you paste the full code ?
>
[quoted text clipped - 75 lines]
>
> - 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 - 25 Apr 2008 15:27 GMT
use...

imgFrom.Visible = false

Signature

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?

Doogie - 25 Apr 2008 15:50 GMT
On Apr 25, 9:27 am, "David"
<david.colliver.N...@revilloc.REMOVETHIS.com> wrote:
> use...
>
[quoted text clipped - 37 lines]
>
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.