Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
 
I have the code below which is meant to populate a textbox with the date of birth from an asp calendar but the calendar keeps disappearing when i try to change the month. I would appreciate any suggestion to fix this as i am new to asp.
 
Thanks
 
...Register.aspx
<asp:Content ID="Content1" runat="server" contentplaceholderid="ContentPlaceHolder1" EnableViewState="True">
    <script type="text/javascript">
        function popupCalendar() {
            var dateField = document.getElementById('dateField');
 
            // toggle the div
            if (dateField.style.display == 'none')
                dateField.style.display = 'block';
            else
                dateField.style.display = 'none';
        }
</script>
 
<h2 style="text-align: center">ADD STAFF</h2><br />
    <div class="container">
    <fieldset> <legend>Personal Details</legend>
 
    <asp:Panel ID="Panel1" runat="server">
        <table border="0" id="table2">
 

            <tr>
                <td class="td1">Date Of Birth </td>
                <td class="td2"><asp:TextBox ID="CalTxt" runat="server" AutoPostBack="True" MaxLength="20" /><img src="Images/date.ico" onclick="popupCalendar()" style="height: 30px" />  </td>
 

            </tr>
 
        </table>
 
    </asp:Panel>
        </fieldset>
        </div>
 

 
    <div id="dateField" style="display:none;">
 
        <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="SelectionChanged_Date"></asp:Calendar>
</div>
 

</asp:Content>
 

 
Register.aspx.cs
protected void Page_Load(object sender, EventArgs e)
        {
 
        }
        protected void SelectionChanged_Date(object sender, EventArgs e)
        {
            string date = Calendar1.SelectedDate.ToString("dd/MM/yyyy");
 
            CalTxt.Text = date.ToString();
 
        }
Posted 28-Mar-13 8:39am
Timtope335
Edited 28-Mar-13 9:20am
v2
Comments
Prasad Khandekar at 28-Mar-13 15:13pm
   
Hello,
 
The calendar is disappearing because on change of month it's triggering a postback. You can try adding code similar to shown below in your page_load to keep the calendar visible.
 
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (txtDate.Text == "")
dateField.Style["display"] = "block";
else
dateField.Style["display"] = "none";
 
}
}
 
Regards,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 152
2 ProgramFOX 130
3 Maciej Los 130
4 den2k88 80
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100