Watermark / hint / placeholder text in TextBox?

How can I put some text into a TextBox which will be removed automatically when the user types something in it? 34 Answers 34 You can create a watermark that can be added to any TextBox with an Attached Property. Here is the source for the Attached Property: using System; using System.Collections.Generic; using System.ComponentModel; using … Read more

How do I get a TextBox to only accept numeric input in WPF?

I’m looking to accept digits and the decimal point, but no sign. I’ve looked at samples using the NumericUpDown control for Windows Forms, and this sample of a NumericUpDown custom control from Microsoft. But so far it seems like NumericUpDown (supported by WPF or not) is not going to provide the functionality that I want. … Read more

How can I set focus on an element in an HTML form using JavaScript?

I have a web form with a text box in it. How do I go about setting focus to the text box by default? Something like this: <body onload=’setFocusToTextBox()’> so can anybody help me with it? I don’t know how to set focus to the text box with JavaScript. <script> function setFocusToTextBox(){ //What to do … Read more