<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>chillijam.co.uk &#187; ASP</title>
	<atom:link href="http://chillijam.co.uk/tag/asp/feed/" rel="self" type="application/rss+xml" />
	<link>http://chillijam.co.uk</link>
	<description></description>
	<lastBuildDate>Thu, 26 Jan 2012 15:01:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Hint text in ASP.NET TextBox controls</title>
		<link>http://chillijam.co.uk/2008/06/03/hint-text-in-aspnet-textbox-controls/</link>
		<comments>http://chillijam.co.uk/2008/06/03/hint-text-in-aspnet-textbox-controls/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 14:44:11 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[microsoft]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[Javascrip]]></category>

		<guid isPermaLink="false">http://chillijam.co.uk/?p=18</guid>
		<description><![CDATA[More and more often these days, you see hint text in a textbox control on a web form.  You know the kind of thing &#8211; &#8220;user name&#8221; or &#8220;password&#8221; appearing in silver text within an input control.  Well, I had &#8230; <a href="http://chillijam.co.uk/2008/06/03/hint-text-in-aspnet-textbox-controls/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>More and more often these days, you see hint text in a textbox control on a web form.  You know the kind of thing &#8211; &#8220;user name&#8221; or &#8220;password&#8221; appearing in silver text within an input control.  Well, I had to implement that functionality today and it is surprisingly easy to achieve.</p>
<p>The first thing you need to do is create your TextBox control on the page.  Once you&#8217;ve done that, add the following method to your codebehind file.</p>
<p>private void SetTextBoxHints(TextBox textBox, string defaultText)<br />
{<br />
textBox.Attributes.Add(&#8220;onfocus&#8221;, &#8220;clearText(this,&#8217;&#8221; + defaultText + &#8220;&#8216;)&#8221;);<br />
textBox.Attributes.Add(&#8220;onblur&#8221;, &#8220;resetText(this,&#8217;&#8221; + defaultText + &#8220;&#8216;)&#8221;);<br />
if (textBox.Text == &#8220;&#8221;)<br />
{<br />
textBox.Text = defaultText;<br />
textBox.ForeColor = System.Drawing.Color.Silver;<br />
}<br />
else if (textBox.Text == defaultText)<br />
{<br />
textBox.ForeColor = System.Drawing.Color.Silver;<br />
}<br />
else<br />
{<br />
textBox.ForeColor = System.Drawing.Color.Black;</p>
<p>}</p>
<p> Next, you&#8217;ll need to add the javascript to the page/user control to look after the dynamic changes in content/colour. </p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;
&lt;!--
function clearText(ctrl,defaultText) {
if(ctrl.value == defaultText)
ctrl.value = &quot;&quot;
ctrl.style.color = &quot;#000000&quot;;
}
function resetText(ctrl,defaultText) {
if(ctrl.value == &quot;&quot;)
{
 ctrl.value = defaultText
 ctrl.style.color = &quot;#C0C0C0&quot;;
}
}
// --&gt;
&lt;/script&gt;</pre>
<p>Then, you need to call the setup method for each Textbox you want to control.</p>
<pre>
<pre>
SetTextBoxHints(myControl, "the text you want to show as default...");
</pre>
<p><span style="font-size: x-small;">And that, as they say, is that.  Enjoy.</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://chillijam.co.uk/2008/06/03/hint-text-in-aspnet-textbox-controls/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

