BeanSoftware Logo

ASP.NET Database Search Control

    Write For Us

How To Make Moving Text On Web Form?

Let say you want to create welcome message or some announcement message. In some cases, this message will be more effective if text is moving over the form in some direction, like this message bellow:

Hello visitor, this is a message that goes to left.
And this is the message that goes to right.
This message
goes from
bottom to top.
But this
message is going
to down.


To achieve this, you need to use <marquee > HTML tag. To specify direction, you need to use its direction attribute. So, to create first message, you can use this code:

<marquee direction="left">Hello visitor, this is a message that goes to left.</marquee>


Direction attribute have 4 possible values: left, right, up and down.

You can manipulate marquee tag with ASP.NET server side code. To do this, you need to add runat="server" attribute and set id attribute to some meaningful value, like this:

<marquee id="MyMovingText" runat="server" direction="left"></marquee>


Then, on server side, you can edit its message with code like this:

[ C# ]

MyMovingText = "Hello " + strUserName;

[ VB.NET ]

MyMovingText = "Hello " & strUserName


Marquee tag remarks

If you type <marquee > tag in Visual Studio IDE, you'll see that is underlined with green color and warning message: Validation (XHTML 1.0 Transitional): Element 'marquee' is not supported. So, marquee tag will not pass validation, but it will show in last versions of major web browsers. Depending of your needs, you can decide to simply ignore this message as it is not so much important.

If you need marquee solution with more compatibility I suggest you to check Cross Browser Marquee from DynamicDrive. Note that their solution is based on JavaScript, so although it will work on some older versions of Mozilla browsers it will not work on any new or old web browser if visitor is disabled JavaScript.

You are not limited to plain text inside marquee. Inside tags can be any HTML, like hyperlinks, images, css formated content etc.

Happy programming!

Related articles:

1. Cascaded Style Sheets (CSS) in ASP.NET Web applications

FAQ toolbar: Submit FAQ  |  Tell A Friend  |  Add to favorites  |  Feedback

Copyright © 2002-2008 Bean Software. All rights reserved.