ASP Calendar Date Pick
- by Steven
I am attempting to construct my own date picker using code from several sources. Specifically, I am now populating the textbox with a calendar click.
Two questions:
Why does the first click refresh the page without doing anything?
How can I have the textbox update without refreshing the entire page?
myDate.ascx
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="myDate.ascx.vb"
Inherits="Website.myDate" %>
<script language="javascript" type="text/javascript">
function toggleCalendar(myID) {
var obj = document.getElementById(myID)
obj.style.display = (obj.style.display == "none") ? "" : "none";
}
</script>
<asp:TextBox ID="dateText" runat="server" > </asp:TextBox>
<input type="button" name="dateBtn" value="x"
onclick="toggleCalendar('<%=dateCal.clientID%>');" />
<asp:Calendar ID="dateCal" runat="server" ></asp:Calendar>
myDate.ascx.vb
Partial Public Class myDate
Inherits System.Web.UI.UserControl
Protected Sub dateCal_SelectionChanged _
(ByVal sender As Object, ByVal e As EventArgs) _
Handles dateCal.SelectionChanged
dateText.Text = dateCal.SelectedDate 'update text box'
dateCal.Style("display") = "none" 'hide calendar'
End Sub
End Class