<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Travis Collins </title><subtitle type="html" /><id>http://weblogs.asp.net/traviscollins/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/traviscollins/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/traviscollins/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2008-02-11T10:15:00Z</updated><entry><title>ASP.NET Labels with Associated Controls inside of User Controls</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/traviscollins/archive/2008/03/03/asp-net-labels-with-associated-controls-inside-of-user-controls.aspx" /><id>http://weblogs.asp.net/traviscollins/archive/2008/03/03/asp-net-labels-with-associated-controls-inside-of-user-controls.aspx</id><published>2008-03-03T14:21:00Z</published><updated>2008-03-03T14:21:00Z</updated><content type="html">&lt;p&gt;I've been trying to use labels with the AssociatedControlID property more often.&amp;#160; If you aren't familiar with this property, it changes the behavior of the Label control.&amp;#160; Rather than rendering the typical &amp;lt;span&amp;gt; html element, the Label control will now render a &amp;lt;label&amp;gt; html element with the &lt;strong&gt;for&lt;/strong&gt; property set.&amp;#160; This links the label to another server control.&amp;#160; This is good for accessibility, allows hotkeys to be set for the associated control, and also allows the user to click on the label in order to give focus to the associated control. Syntax is as follows&lt;/p&gt;  &lt;div style="border: gray 1px solid; overflow: auto; width: 97.5%; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4;"&gt;&lt;pre&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:Label&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;u&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;S&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;u&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;earch&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AssociatedControlID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtSearch&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;AccessKey&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;s&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;lblSearch&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txtSearch&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In this example, pressing Alt+S (or Ctrl+Alt+S in Firefox), or clicking on the label will give focus to the textbox.&lt;/p&gt;

&lt;p&gt;But what if the control you want to target is actually inside of an user control.&amp;#160; This is the problem that I faced recently.&amp;#160; Lets say you have an instance of an user control with the id &lt;strong&gt;EmailInput1&lt;/strong&gt;.&amp;#160; This user control has a textbox &lt;strong&gt;txtEmail&lt;/strong&gt;.&amp;#160; To target this textbox from your aspx page, set the AssociatedControlID property to &amp;quot;&lt;strong&gt;EmailInput1:txtEmail&lt;/strong&gt;&amp;quot;.&amp;#160; Just parent -&amp;gt; child with a colon separator.&amp;#160; Easy enough!&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5903413" width="1" height="1"&gt;</content><author><name>travistx</name><uri>http://weblogs.asp.net/members/travistx.aspx</uri></author><category term="ASP.NET" scheme="http://weblogs.asp.net/traviscollins/archive/tags/ASP.NET/default.aspx" /><category term="Accessibility" scheme="http://weblogs.asp.net/traviscollins/archive/tags/Accessibility/default.aspx" /></entry><entry><title>AJAX Timeout Server Control</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/traviscollins/archive/2008/02/22/ajax-timeout-server-control.aspx" /><id>http://weblogs.asp.net/traviscollins/archive/2008/02/22/ajax-timeout-server-control.aspx</id><published>2008-02-22T13:44:00Z</published><updated>2008-02-22T13:44:00Z</updated><content type="html">&lt;P&gt;Don't you hate it when you are idle on a web app for just a bit too long, and your membership session gets timed out without warning?&amp;nbsp; Your users sure do!&amp;nbsp; Often times the user may not even realize he has been timed out until he finishes completing a form, and clicks the submit button.&amp;nbsp; At which time not only has the user lost his session, he has lost his data too.&lt;/P&gt;
&lt;P&gt;In this post, I will provide a custom control, complete with source code, which will improve this experience for your users by displaying a nice message to inform them that their session is about to expire.&amp;nbsp; It will do this without any popups or postbacks by using the &lt;A href="http://www.asp.net/ajax/" mce_href="http://www.asp.net/ajax/"&gt;ASP.NET AJAX framework&lt;/A&gt;.&amp;nbsp; &lt;STRONG&gt;Download the control, and source code, &lt;A href="http://weblogs.asp.net/blogs/traviscollins/Examples/TSC.Timeout.zip" mce_href="http://weblogs.asp.net/blogs/traviscollins/Examples/TSC.Timeout.zip"&gt;here&lt;/A&gt;.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/traviscollins/WindowsLiveWriter/TimeoutServerControl_A514/timeout1_6.jpg" mce_href="http://weblogs.asp.net/blogs/traviscollins/WindowsLiveWriter/TimeoutServerControl_A514/timeout1_6.jpg"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=25 alt=timeout1 src="http://weblogs.asp.net/blogs/traviscollins/WindowsLiveWriter/TimeoutServerControl_A514/timeout1_thumb_2.jpg" width=534 border=0 mce_src="http://weblogs.asp.net/blogs/traviscollins/WindowsLiveWriter/TimeoutServerControl_A514/timeout1_thumb_2.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Implementation is easy. Just add the control to your Visual Studio toolbox, and drag it on to your master page wherever you would like the message to appear. Set the properties to your situation and enter markup into the template section as seen here:&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: gray 1px solid; PADDING-RIGHT: 4px; BORDER-TOP: gray 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 8pt; PADDING-BOTTOM: 20px; MARGIN: 20px 0px 10px; OVERFLOW: auto; BORDER-LEFT: gray 1px solid; WIDTH: 97.5%; CURSOR: text; LINE-HEIGHT: 12pt; PADDING-TOP: 4px; BORDER-BOTTOM: gray 1px solid; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BACKGROUND-COLOR: #f4f4f4"&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;tsc:Timeout&lt;/SPAN&gt; 
    &lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Timeout1"&lt;/SPAN&gt; 
    &lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt;
    &lt;SPAN style="COLOR: #ff0000"&gt;Enabled&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;/SPAN&gt;
    &lt;SPAN style="COLOR: #ff0000"&gt;AboutToTimeoutMinutes&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="28"&lt;/SPAN&gt; 
    &lt;SPAN style="COLOR: #ff0000"&gt;TimeoutMinutes&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="30"&lt;/SPAN&gt; 
    &lt;SPAN style="COLOR: #ff0000"&gt;TimeoutURL&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="~/Default.aspx?timeout=true"&lt;/SPAN&gt;
    &lt;SPAN style="COLOR: #ff0000"&gt;CssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="timeout"&lt;/SPAN&gt; 
    &lt;SPAN style="COLOR: #ff0000"&gt;DisplayButton&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"&lt;/SPAN&gt; 
    &lt;SPAN style="COLOR: #ff0000"&gt;ButtonCssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="btn"&lt;/SPAN&gt; 
    &lt;SPAN style="COLOR: #ff0000"&gt;ButtonText&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Continue My Session!"&lt;/SPAN&gt;
    &lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Template&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;
        For your safety and protection, your session is about to expire.  If you wish to continue your session, please click here.
    &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Template&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;tsc:Timeout&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;This control needs the &lt;A href="http://www.asp.net/ajax/" mce_href="http://www.asp.net/ajax/"&gt;ASP.NET AJAX framework&lt;/A&gt; to be included in your project.&amp;nbsp; It will also require a Script Manager control.&amp;nbsp; Following is a description of each property&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Enabled&lt;/STRONG&gt; - Whether the control is enabled or not.&amp;nbsp; I typically place the control on a master page, and set the enabled property in code behind based on whether the user is logged in or not.&amp;nbsp; If they are not logged in, they can't very well timeout can they? &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;AboutToTimeoutMinutes&lt;/STRONG&gt; - Idle minutes until the user is informed that their session is about to time out. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;TimeoutMinutes&lt;/STRONG&gt; - Idle minutes until the membership session will time out.&amp;nbsp; This should match the forms authentication timeout property in the web.config. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;TimeoutURL&lt;/STRONG&gt; - URL to redirect the user, in the event of a membership session timeout &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;CssClass&lt;/STRONG&gt; - CSS class name applied to the control &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;DisplayButton&lt;/STRONG&gt; - Whether the button is visible.&amp;nbsp; If this is false, the entire control is clickable by the user to restore their session.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;ButtonCssClass&lt;/STRONG&gt; - CSS class name applied to the button control &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;ButtonText&lt;/STRONG&gt; - The text to be displayed on the button &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Template&lt;/STRONG&gt; - Enter your html or asp.net markup here.&amp;nbsp; This is the message that will be displayed when the user's membership session is about to timeout. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Enjoy, and please post here if you see any room for improvement in the source.&amp;nbsp; This is my first attempt at a AJAX enabled custom control.&amp;nbsp; &lt;STRONG&gt;Download the control, and source code, &lt;A href="http://weblogs.asp.net/blogs/traviscollins/Examples/TSC.Timeout.zip" mce_href="http://weblogs.asp.net/blogs/traviscollins/Examples/TSC.Timeout.zip"&gt;here&lt;/A&gt;.&lt;/STRONG&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5838635" width="1" height="1"&gt;</content><author><name>travistx</name><uri>http://weblogs.asp.net/members/travistx.aspx</uri></author><category term="Membership" scheme="http://weblogs.asp.net/traviscollins/archive/tags/Membership/default.aspx" /><category term="AJAX" scheme="http://weblogs.asp.net/traviscollins/archive/tags/AJAX/default.aspx" /><category term="ASP.NET" scheme="http://weblogs.asp.net/traviscollins/archive/tags/ASP.NET/default.aspx" /><category term="Server Control" scheme="http://weblogs.asp.net/traviscollins/archive/tags/Server+Control/default.aspx" /><category term="Custom Control" scheme="http://weblogs.asp.net/traviscollins/archive/tags/Custom+Control/default.aspx" /></entry><entry><title>Dramatic Password Reveal - in ASP.NET</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/traviscollins/archive/2008/02/13/dramatic-password-reveal-in-asp-net.aspx" /><id>http://weblogs.asp.net/traviscollins/archive/2008/02/13/dramatic-password-reveal-in-asp-net.aspx</id><published>2008-02-13T22:49:42Z</published><updated>2008-02-13T22:49:42Z</updated><content type="html">&lt;p&gt;&lt;a href="http://www.codinghorror.com"&gt;Jeff Atwood&lt;/a&gt; recently &lt;a href="http://www.codinghorror.com/blog/archives/001056.html"&gt;blogged&lt;/a&gt; about a nice feature of Vista, when you are entering your wireless network key.&amp;#160; This feature provides the user with a checkbox to toggle the obfuscation of the wireless key being entered.&lt;/p&gt;  &lt;p&gt;As Jeff mentions, this is a nice technique, and one that I have recently investigated for my own web applications. However, doing this on the web is a little trickier because you aren't able to change the type attribute of an input element using JavaScript.&amp;#160; Shown below, I have developed a way to accomplish the same result.&lt;/p&gt;  &lt;p&gt;First, surround your password text field with a simple span&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 20px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;span&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;spanPass&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;asp:TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Password&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;TextMode&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Password&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;txt&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;span&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Add a checkbox to toggle the password obfuscation&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 20px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;input&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;checkbox&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;chkReveal&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;onclick&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;toggleReveal();&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;label&lt;/span&gt; &lt;span style="color: #ff0000"&gt;for&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;chkReveal&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;Reveal my password&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;label&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Finally a bit of JavaScript, and we're done&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 20px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;script type=&lt;span style="color: #006080"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&amp;gt;
    &lt;span style="color: #0000ff"&gt;function&lt;/span&gt; toggleReveal()
    {
        &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; chkReveal = $get(&lt;span style="color: #006080"&gt;'chkReveal'&lt;/span&gt;);
        &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; txt = $get(&lt;span style="color: #006080"&gt;'&amp;lt;%= this.Login1.FindControl(&amp;quot;Password&amp;quot;).ClientID %&amp;gt;'&lt;/span&gt;);
        &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; spanPass = $get(&lt;span style="color: #006080"&gt;'spanPass'&lt;/span&gt;);
        
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (chkReveal.&lt;span style="color: #0000ff"&gt;checked&lt;/span&gt;)
            spanPass.innerHTML = &lt;span style="color: #006080"&gt;'&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;'&lt;/span&gt; + txt.name + &lt;span style="color: #006080"&gt;'&amp;quot; id=&amp;quot;'&lt;/span&gt; + txt.id + &lt;span style="color: #006080"&gt;'&amp;quot; value=&amp;quot;'&lt;/span&gt; + txt.value + &lt;span style="color: #006080"&gt;'&amp;quot; class=&amp;quot;'&lt;/span&gt;+ txt.className +&lt;span style="color: #006080"&gt;'&amp;quot; /&amp;gt;'&lt;/span&gt;;
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
            spanPass.innerHTML = &lt;span style="color: #006080"&gt;'&amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;'&lt;/span&gt; + txt.name + &lt;span style="color: #006080"&gt;'&amp;quot; id=&amp;quot;'&lt;/span&gt; + txt.id + &lt;span style="color: #006080"&gt;'&amp;quot; value=&amp;quot;'&lt;/span&gt; + txt.value + &lt;span style="color: #006080"&gt;'&amp;quot; class=&amp;quot;'&lt;/span&gt;+ txt.className +&lt;span style="color: #006080"&gt;'&amp;quot; /&amp;gt;'&lt;/span&gt;;
    }
&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Note I am using the handy $get which comes with ASP.NET AJAX.&amp;#160; If you are not using this framework, you can just as easily replace $get with document.getElementById().&amp;#160; &lt;/p&gt;

&lt;p&gt;This small JavaScript method simply rewrites the contents of the span tag with a new input control, copying the previous name, id, value, and class values.&amp;#160; The only thing that gets changed is the type attribute.&amp;#160; Now I know what you're thinking, and no, JavaScript is not able to change the type attribute directly.&lt;/p&gt;

&lt;p&gt;I have tested this in IE6, IE7, Firefox and Safari.&amp;#160; It works as expected in all of these browsers.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5781436" width="1" height="1"&gt;</content><author><name>travistx</name><uri>http://weblogs.asp.net/members/travistx.aspx</uri></author><category term="Membership" scheme="http://weblogs.asp.net/traviscollins/archive/tags/Membership/default.aspx" /><category term="ASP.NET" scheme="http://weblogs.asp.net/traviscollins/archive/tags/ASP.NET/default.aspx" /><category term="JavaScript" scheme="http://weblogs.asp.net/traviscollins/archive/tags/JavaScript/default.aspx" /><category term="Usability" scheme="http://weblogs.asp.net/traviscollins/archive/tags/Usability/default.aspx" /></entry><entry><title>Check Username Availability with ASP.NET AJAX</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/traviscollins/archive/2008/02/12/check-username-availability-with-asp-net-ajax.aspx" /><id>http://weblogs.asp.net/traviscollins/archive/2008/02/12/check-username-availability-with-asp-net-ajax.aspx</id><published>2008-02-12T13:49:00Z</published><updated>2008-02-12T13:49:00Z</updated><content type="html">&lt;P&gt;Here is a little trick you can use to spice up your asp.net registration pages. I will use ASP.NET AJAX to inform the user whether the username they have entered is available. Rather than use the UpdatePanel, I will slim down the amount of data going over the wire for each ajax request. I will accomplish this using the PageMethods feature.&lt;/P&gt;
&lt;P&gt;This tutorial assumes that you have a working knowledge of how to start an ASP.NET AJAX web application, drop a script manager control onto your form, and use the CreateUser wizard control, or another method of registering users.&amp;nbsp; A little JavaScript knowledge will help too.&lt;/P&gt;
&lt;P&gt;In order to use PageMethods, I will need to set the EnablePageMethods property to true on my ScriptManager.&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: gray 1px solid; PADDING-RIGHT: 4px; BORDER-TOP: gray 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 8pt; OVERFLOW-X: auto; PADDING-BOTTOM: 20px; MARGIN: 20px 0px 10px; BORDER-LEFT: gray 1px solid; WIDTH: 97.5%; CURSOR: text; LINE-HEIGHT: 12pt; PADDING-TOP: 4px; BORDER-BOTTOM: gray 1px solid; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BACKGROUND-COLOR: #f4f4f4"&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&amp;lt;asp:ScriptManager ID=&lt;SPAN style="COLOR: #006080"&gt;"ScriptManager1"&lt;/SPAN&gt; runat=&lt;SPAN style="COLOR: #006080"&gt;"server"&lt;/SPAN&gt; EnablePageMethods=&lt;SPAN style="COLOR: #006080"&gt;"True"&lt;/SPAN&gt; /&amp;gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;DIV&gt;My registration page is called register.aspx. I will create a static method in the code behind for this page. The method will check to see if a username exists, and return a Boolean indicating whether the username is available or not.&lt;/DIV&gt;
&lt;DIV style="BORDER-RIGHT: gray 1px solid; PADDING-RIGHT: 4px; BORDER-TOP: gray 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 8pt; PADDING-BOTTOM: 4px; MARGIN: 20px 0px 10px; OVERFLOW: auto; BORDER-LEFT: gray 1px solid; WIDTH: 97.5%; CURSOR: text; MAX-HEIGHT: 200px; LINE-HEIGHT: 12pt; PADDING-TOP: 4px; BORDER-BOTTOM: gray 1px solid; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BACKGROUND-COLOR: #f4f4f4"&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;[WebMethod]
&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; IsUserAvailable(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; username) 
{
    MembershipUser usr = Membership.GetUser(username);
     &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; (usr == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;);
}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;The WebMethod attribute is needed to mark this as a method that can be executed from Javascript.&lt;/P&gt;
&lt;P&gt;Now I will go ahead and create some markup create some markup for my username field on your registration page. Something like this should do.&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: gray 1px solid; PADDING-RIGHT: 4px; BORDER-TOP: gray 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 8pt; OVERFLOW-X: auto; PADDING-BOTTOM: 20px; MARGIN: 20px 0px 10px; BORDER-LEFT: gray 1px solid; WIDTH: 97.5%; CURSOR: text; MAX-HEIGHT: 200px; LINE-HEIGHT: 12pt; PADDING-TOP: 4px; BORDER-BOTTOM: gray 1px solid; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BACKGROUND-COLOR: #f4f4f4"&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:Label&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="lblUserName"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;AssociatedControlID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="UserName"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;Desired Username&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:Label&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;asp:TextBox&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="UserName"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;CssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="txt"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;onkeyup&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="usernameChecker(this.value);"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;
&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;span&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;id&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="spanAvailability"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;span&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;There are a couple of things to take note of here. The onkeyup javascript event will be fired every keypress, and will be used to check the availability of the username entered.&amp;nbsp; Also take note of the span with an id of spanAvailability. The JavaScript will use this span to write output letting the user know whether the username is available.&lt;/P&gt;
&lt;P&gt;Here's the last part, the Javascript that wires everything together.&amp;nbsp; I will insert this at the bottom of my register.aspx page:&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: gray 1px solid; PADDING-RIGHT: 4px; BORDER-TOP: gray 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 8pt; PADDING-BOTTOM: 20px; MARGIN: 20px 0px 10px; OVERFLOW: auto; BORDER-LEFT: gray 1px solid; WIDTH: 97.5%; CURSOR: text; LINE-HEIGHT: 12pt; PADDING-TOP: 4px; BORDER-BOTTOM: gray 1px solid; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BACKGROUND-COLOR: #f4f4f4"&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&amp;lt;script type=&lt;SPAN style="COLOR: #006080"&gt;"text/javascript"&lt;/SPAN&gt;&amp;gt;
&lt;SPAN style="COLOR: #0000ff"&gt;var&lt;/SPAN&gt; usernameCheckerTimer;
&lt;SPAN style="COLOR: #0000ff"&gt;var&lt;/SPAN&gt; spanAvailability = $get(&lt;SPAN style="COLOR: #006080"&gt;"spanAvailability"&lt;/SPAN&gt;);

&lt;SPAN style="COLOR: #0000ff"&gt;function&lt;/SPAN&gt; usernameChecker(username) 
{
    clearTimeout(usernameCheckerTimer);
    &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (username.length == 0)
        spanAvailability.innerHTML = &lt;SPAN style="COLOR: #006080"&gt;""&lt;/SPAN&gt;;
    &lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt;
    {
        spanAvailability.innerHTML = &lt;SPAN style="COLOR: #006080"&gt;"&amp;lt;span style='color: #ccc;'&amp;gt;checking...&amp;lt;/span&amp;gt;"&lt;/SPAN&gt;;
        usernameCheckerTimer = setTimeout(&lt;SPAN style="COLOR: #006080"&gt;"checkUsernameUsage('"&lt;/SPAN&gt; + username + &lt;SPAN style="COLOR: #006080"&gt;"');"&lt;/SPAN&gt;, 750);
    }
}

&lt;SPAN style="COLOR: #0000ff"&gt;function&lt;/SPAN&gt; checkUsernameUsage(username) 
{
    &lt;SPAN style="COLOR: #008000"&gt;// initiate the ajax pagemethod call&lt;/SPAN&gt;
    &lt;SPAN style="COLOR: #008000"&gt;// upon completion, the OnSucceded callback will be executed&lt;/SPAN&gt;
    PageMethods.IsUserAvailable(username, OnSucceeded);
}

&lt;SPAN style="COLOR: #008000"&gt;// Callback function invoked on successful completion of the page method.&lt;/SPAN&gt;
&lt;SPAN style="COLOR: #0000ff"&gt;function&lt;/SPAN&gt; OnSucceeded(result, userContext, methodName) 
{
    &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (methodName == &lt;SPAN style="COLOR: #006080"&gt;"IsUserAvailable"&lt;/SPAN&gt;)
    {
        &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (result == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            spanAvailability.innerHTML = &lt;SPAN style="COLOR: #006080"&gt;"&amp;lt;span style='color: DarkGreen;'&amp;gt;Available&amp;lt;/span&amp;gt;"&lt;/SPAN&gt;;
        &lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt;
            spanAvailability.innerHTML = &lt;SPAN style="COLOR: #006080"&gt;"&amp;lt;span style='color: Red;'&amp;gt;Unavailable&amp;lt;/span&amp;gt;"&lt;/SPAN&gt;;
    }
}
&amp;lt;/script&amp;gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;This effect is pretty easy to do, and adds a nice value to the user experience.&amp;nbsp; I hope you are able to find use for this technique in your applications.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Update:&lt;/STRONG&gt;&amp;nbsp;Download a sample project &lt;A class="" title=here href="http://weblogs.asp.net/blogs/traviscollins/Examples/CheckUsernameWithAJAX.zip" mce_href="http://weblogs.asp.net/blogs/traviscollins/Examples/CheckUsernameWithAJAX.zip"&gt;here&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Unit next time,&lt;/P&gt;
&lt;P&gt;Travis&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5763723" width="1" height="1"&gt;</content><author><name>travistx</name><uri>http://weblogs.asp.net/members/travistx.aspx</uri></author><category term="Membership" scheme="http://weblogs.asp.net/traviscollins/archive/tags/Membership/default.aspx" /><category term="PageMethods" scheme="http://weblogs.asp.net/traviscollins/archive/tags/PageMethods/default.aspx" /><category term="AJAX" scheme="http://weblogs.asp.net/traviscollins/archive/tags/AJAX/default.aspx" /><category term="ASP.NET" scheme="http://weblogs.asp.net/traviscollins/archive/tags/ASP.NET/default.aspx" /></entry><entry><title>There Goes The Neighborhood</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/traviscollins/archive/2008/02/11/there-goes-the-neighborhood.aspx" /><id>http://weblogs.asp.net/traviscollins/archive/2008/02/11/there-goes-the-neighborhood.aspx</id><published>2008-02-11T16:15:00Z</published><updated>2008-02-11T16:15:00Z</updated><content type="html">Well I've decided to join the blogging trend, and hopefully pay it forward with some help to the community. This should also force me to more thoroughly research topics which interest me. Keep an eye on this space for the latest things I've learned in .NET, ASP.NET, Visual Studio, AJAX, or whatever technology I happen to be using today. We'll see how long this lasts... XOXO Travis...(&lt;a href="http://weblogs.asp.net/traviscollins/archive/2008/02/11/there-goes-the-neighborhood.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5760769" width="1" height="1"&gt;</content><author><name>travistx</name><uri>http://weblogs.asp.net/members/travistx.aspx</uri></author></entry></feed>