Solved

Greyed Out Text and ASP.net

Posted on 2013-01-20
3
626 Views
Last Modified: 2013-01-21
I would like to, have greyed out text in a textBox when the web application starts.  When someone clicks on the textBox I would like the greyed out text to be removed so that they can type, and if they leave the textBox, I would like this greyed out text to return.

How can I achieve this in Web developer Express, using VB ?

Thanks
0
Comment
Question by:ndr-itsolutions
3 Comments
 
LVL 6

Accepted Solution

by:
esolve earned 300 total points
ID: 38798557
You can achieve this by using an input control. Just add an id and runat=server so that it can behave like a server control.

You can then access the txtUser.Value of the control in code behind.

<input name="txtUser" type="text" id="txtUser" runat="server" value="username" onblur="if(this.value==&#39;&#39;)this.value=this.defaultValue;" onfocus="if(this.value==this.defaultValue)this.value=&#39;&#39;;" />

Additionally you can add a css class to modify the text appearance. eg.

class="login-block"

<style>
        .login-block {
            background: none;
            color: #5d5858;
            width: 145px;
            margin: 5px;
            text-transform: capitalize !important;
            font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
        }
    </style>
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38798836
Try this,
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="greyedTxtbox.aspx.vb" Inherits="greyedTxtbox" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
    .blurStyle
    {
        font-size:15px;
        color:gray;
    }
    .focusStyle
    {
        font-size:15px;
        color:Black;
    }
        
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" onblur="this.className='blurStyle';" onFocus="this.className='focusStyle';"
        class="blurStyle" Text="Hi test"></asp:TextBox>
    </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 38799918
just use a javascript on onchange event at the text box

example:

 <asp:TextBox ID="TextBox1" runat="server" onchange="ChangeColor()"  ></asp:TextBox>

the javascript function will look like this

  <script language="javascript" type="text/javascript">

function ChangeColor()
{TextBox1= "<%=TextBox1.ClientID %>"
 document.getElementById(TextBox1).style.color='grey'

}
</script>
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Add or delete table rows 10 54
Load data upon clicking a button 8 35
Convert Ctime to date time in textfile? 7 32
.NET Enums [Flags] & Bitwise Design Question 6 28
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question