Changing a Server Control's Property when it loses focus

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?
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,134
Latest member
Lou6777736
Top