ASP.NET TextBox control with label text in the background - asp.net

I'm creating a login page. I want to create ASP.NET TextBox controls that have "Username" and "Password" as their Text, but as soon as they receive focus, these words should disappear and whatever the user types should appear, just like normal textbox. If the user leaves it blank and tabs to the next textbox, then these words appear again. This will eliminate the need for having separate labels in front of the text boxes. I would appreciate if someone can share their expertise for doing this.

Use the TextBox Watermark Extender that's in Microsoft's AJAX Toolkit.

Google "ASP.NET Watermark textbox". Theres a ton of implemnentations

Related

How to control textbox display

How can I make ASP textboxes be in a horizontal form? I want to know the code that will enable my textboxes to be in a straight line horizontally and not vertically.
Both, ASP and HTML textboxes are inline elements normally. In a new webform with empty template in ASP.NET just move into design tab and place a new Textbox. Click somewhere else, but remain inside the div, so that no control remains selected. Your cursor would be after the Textbox you just created, and the div is showing focus. Pick and drop another Textbox now. If everything is going correct, You will see two textboxes side by side.
No extra coding or css property required.
Here is a post by Microsoft
https://learn.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/creating-a-basic-web-forms-page#to-add-controls-to-the-page
In the Microsoft's post above, you can instead of placing a button, place a textbox.

How to have default text for textbox and making it fade away only when user types something

I am having Asp.Net Textboxes for my contact form.How can I have a default text for my textbox and make the text fade away when the user types something and not on focus , just like SO search box for example.I think it is different from textbox watermark.Any suggestions are welcome , thanks.
This doesn't answer your question, but rectifies part of your question.
just like SO search box for example
The SO Search box uses HTML 5 placeholder attribute, and the functionality you're seeing is Chrome specific.
User agents should present this hint to the user, after having
stripped line breaks from it, when the element's value is the empty
string and/or the control is not focused (e.g. by displaying it inside
a blank unfocused control and hiding it otherwise).
The bold part states that the functionality should remove the placeholder text IF the value is empty and/or it's not focused.
Chrome has decided to implement this as 'when it's not empty, remove the placeholder' but if the textbox is focused and empty, the placeholder remains.
Other browsers (IE/Firefox/Opera) remove the placeholder on focus.
You can use Ajax Toolkit TextBoxWatermark Extender
I suggest using AJAXTOOLKIT for this
specifically TextBoxWatermark
You can achieve using TextBoxWatermark in ajax control toolkit

Focus Jumps to Address

I am working on an ASP.NET 2.0 (VB) web application. I am having trouble controlling tab behavior.
TabIndex is set throughout the form and tabs as expected.
But,after making a change in a textbox and hitting Tab or Enter, the focus jumps to the web address bar instead of the next field.
I have tried:
1.SetFocus on the text change event
2.Saving last field name in a hidden textbox and set focus to saved textbox name on Page Load if Post back
3.SetFocus on Pre_render
Still, focus jumps to browser address bar on tab or enter.
I think it may be losing the tab index on post-back.
Any clues?
Thanks in advance, any help is appreciated
When you have AutoPostBack on a TextBox control with TabIndex assigned it could be a little complex to manipulate the Focus. Check out this tutorial which will show you a little trick to Shift Focus to the next control.
Good luck!

asp.net login layout and positioning

I'm using asp.net's login control; two textboxes with the labels on the left and a button beneath (the control renders as a table with 3 rows). When the user enters an incorrect login, the page is posted back and the failure text "incorrect login" is displayed by adding a row between the password textbox and the button.
The problem is that when the failure text is displayed, the new row that's inserted shifts the button down slightly.
It looks odd and off. How can I rearrange this so that when the failure text appears it doesn't shift the login button.
Thanks for your suggestions.
Check out the documentation for the Login control.
Assuming there isn't CSS or markup on the page causing the shifting, you should be able to control the style of the failure text via FailureTextStyle property.
Ok, if anyone gets to this page because of a layout problem with the login control, it's actually pretty easy to solve. By default, the control renders as a table and there's nothing you can do to change the layout of the default control because you don't have access to the HTML.
You need to switch the page to design mode and on the control, click "Convert to Template". When you go back to the source page, the HTML becomes accessible and you can see the HTML of the table that contains the various asp controls. Yank the table and put the control inside divs that you control!

Get element text before page reloads in ASP.net web forms

I am unfortunately having to work with asp.net web forms. I have a label that has a different Text property every time the page loads. I have a button that is clicked. I have double clicked on the button and it has shown me a code view.
I get a reference to the label via labelID.Text, but it refers to the value of the text that is about to be displayed on the next page load. How would I get the text of the value when the button was actually clicked? Or is web forms not advanced enough for that.
Search where the labelID.Text is modified (maybe Page_Load event), and save the text before in a global variable.
It sounds like on every page load or postback, somewhere there is code which applies a new value to labelID.Text. Where is that work being done? Page_Load?
In any case, wherever that work is being done, you most likely have access to both the existing text value of the control, and the new text value you're about to give it.

Resources