Changing a Server Control's Property when it loses focus

  • Thread starter Thread starter jjwhite01
  • Start date Start date
J

jjwhite01

I am working on a web form that contains a Calendar control with an
image button that makes the calendar appear and disappear. However, I
would like to set the visible property of the Calendar control to
false when the control loses focus so that when the user moves to the
next field in the form the calendar disappears. Is there anyway to do
this in ASP.NET or ASP.NET w/ Javascript?
 
Howdy,

Use onblur DOM event of the textbox (i'm assuming control which triggers
calendar to be hidden). You can attach it in the code behing like this:

texBoxVariable.Attributes["onblur"] = "ShowCalendar(false)";

or use expando as below:

<table>
<tr>
<td>Date:<asp:textbox ID="date" runat="server"
onblur="ShowCalendar(false)"/></td>
<td><input type="button" value="..." onclick="ShowCalendar(true)"/></td>
</tr>
<tr>
<td></td>
<td>
<asp:Calendar ID="calendar" runat="server"
Style="position:absolute;display:none"/>
</td>
</tr>
</table>


<script language="javascript">
<!--
function ShowCalendar(visible)
{
var calendar = document.getElementById('<%=calendar.ClientID %>');
if (calendar)
calendar.style.display = visible ? 'block' : 'none';
}
//-->
</script>


hope it helps

Milosz
 
Back
Top