Click here to Skip to main content
15,908,931 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
.....Code on page load ........... in aspx page.............

C#
if (!IsPostBack)
       {
           txtemail.Attributes.Add("value", "Email Id");
           txtpassword.Attributes.Add("value", "Password");
           TextBox1.Attributes.Add("value", "Enter Email Id");
           txtemail.Attributes.Add("onblur", "javascript:if(this.value==''){this.value='Email Id'}");
           txtemail.Attributes.Add("onFocus", "javascript:if(this.value=='Email Id'){this.value=''}");
           TextBox1.Attributes.Add("onblur", "javascript:if(this.value==''){this.value='Enter Email Id'}");
           TextBox1.Attributes.Add("onFocus", "javascript:if(this.value=='Enter Email Id'){this.value=''}");
           txtpassword.Attributes.Add("onblur", "javascript:if(this.value==''){this.value='Password'}");
           txtpassword.Attributes.Add("onFocus", "javascript:if(this.value=='Password'){this.value=''}");

       }


..............html tag.................

XML
<asp:TextBox ID="TextBox1" runat="server" style="text-align: left" Width="151px" Font-Names="Arial"
            Font-Size="Small" ForeColor="#333333" ToolTip="please enter your email ID"
            Font-Bold="True" TabIndex="1"></asp:TextBox>
Posted
Comments
JakirBB 29-Jun-12 8:28am    
When asking a question, make sure that it is clear. You should remember that people can get bored with incomplete question. BTW explain you question mentioning what your problem and what you want to do. Thanks for understanding.
ZurdoDev 29-Jun-12 8:28am    
What's the question?
[no name] 30-Jun-12 23:13pm    
Since you have not defined a mouse click handler for anything, how on earth do you expect to handle it?
Sandeep Mewara 1-Jul-12 4:29am    
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.

Obviously they want a password box to display the word password when its empty.

You should probably just use some plain HTML/JS here and change the type attribute of the input tag to/from text/password.

So when the value attribute is Password the type attribute is set to text and when that changes the type attribute is set to password.

I would try to use jquery. And I'll go ahead and guess the first question you'll have when you mix Jquery with ASP. The ClientID property for the server control(asp:TextBox)is the javascript id within the page.
 
Share this answer
 
v2
On reading couple of times, it looks like you are talking of Watermark textboxes.

Here, look at these:
Existing custom control: AjaxToolkit: TextBoxWatermark Demonstration[^]
Using Javascript & CSS: TextBox Watermark Using JavaScript and CSS[^]
Using jQuery: Create an ASP.NET TextBox Watermark Effect using jQuery[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900