How do 开发者_如何学JAVAyou achieve this. and i set some text inside the textbox. i want it to be lower in opacity and disappear whenever the user clicks on the textbox to begin typing (like in iphone interface). How do i achieve this?
You can use ajax water mark control and jquery autoclear plugin
In html5 a new attribute introduced placeholder, you can make use of this attribute
In aspx markup your TextBox is
<asp:TextBox runat="server" ID="TextBox1"></asp:TextBox>
Then in Page_Load set the attribute.
TextBox1.Attributes.Add("placeholder", "you faded text like in iphone");
Edit 1:
You are right, for right to left text you need to add another dir attribute on TextBox
<asp:TextBox runat="server" ID="TextBox1" dir="rtl"></asp:TextBox>
For the watermark there is the HTML5 placeholder attribute or you could also use a jquery watermark plugin if your site is not yet HTML5. For right to left you may take a look at the following article.
Do it using java script. See the code below:
set a default text for your textbox.
for clearing the textbox call the following function on textbox onblur event
function ClearSearchText() { var searchUserName = document.getElementById('<%=txtUserName.ClientID%>'); if (searchUserName.value = searchUserName.defaultValue) { searchUserName.value = ""; } return false; }
for setting call the following function on textbox onFocus event
function SetSearchText() { var searchUserName = document.getElementById('<%=txtBoxID.ClientID%>'); if (searchUserName.value == "") { searchUserName.value = searchUserName.defaultValue; } } return false; }
- do the search in button postback after checking the default text and also set the textBoxID.Text="your default text".
hope this will help..
精彩评论