any way to hide/show line?

G

Guest

Hi I am trying to show and hide a line dynamically. I setup the line in HTML
using the HR tag but it does not have a visible attribute. Also it does not
allow run at server added to it. Thanks.
 
C

Curt_C [MVP]

Paul said:
Hi I am trying to show and hide a line dynamically. I setup the line in HTML
using the HR tag but it does not have a visible attribute. Also it does not
allow run at server added to it. Thanks.

use a PlaceHolder or even an IMG tag, specifying the height and width.
Heck, you could probably use a DIV or SPAN too
 
E

Elliot M. Rodriguez

I assume its client side youre worrying about? If so then you can place
the HR tag inside a DIV tag and use some javascript to set the DIV's
visibility.

An alternative, if you can set/hide it through postbacks, is to use the
HtmlTextWriter class in System.Web.UI. Or simply use response.write and
spit out the HTML at runtime.
 
D

Dave Fancher

Actually, <HR> does allow Runat="Server". With Runat="Server", <HR> is an
instance of HtmlGenericControl which does have a Visible property. You
could also use .Style["display"] = "none" or "inline" if you still wanted it
to be rendered.

If you look at the documentation of HtmlGenericControl, you'll see that
there's an overload for the constructor that allows you to specify the tag
name so you can dynamically create tags such as <HR> on the fly. There's
also a TagName property for getting or setting the tag name as needed.

One thing to keep in mind is that ASP.NET pages aren't HTML, they're XHTML
and therefore, to be valid, all tags must have a close tag. The runtime
lets you get away with using HTML for non-server-side tags (because
everything not marked as a server tag is treated as a LiteralControl and
streamed to the browser "as is") but for server-side tags (anything marked
as runat="server") you will need the end tag. For tags like <HR>, when you
set Runat="Server", you'll need to write it like this:
<HR runat="server" id="Line1" /> or
<HR runat="server" id="Line1"></HR>

Personally, I prefer the first option because it's more concise.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top