在文本框傍边的下拉日历

在前台的页面为一个控件

<%@ Control Language="c#" AutoEventWireup="false" Codebehind="ctlCalendar.ascx.cs" Inherits="purchaseorders.ctlCalendar" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:textbox id="TextBox1" runat="server" ReadOnly="True" CssClass="text"></asp:textbox>
<input type="button" id="Button1" runat="server" value="" class="text"><br>
<asp:Panel id="pnlCalendar" runat="server">
    
<asp:calendar id="Calendar1" runat="server" BorderColor="White" Font-Names="Verdana" Font-Size="9pt"
        Height
="190px" ForeColor="Black" Width="350px" BackColor="White" BorderWidth="1px" NextPrevFormat="FullMonth">
        
<TodayDayStyle BackColor="#CCCCCC"></TodayDayStyle>
        
<NextPrevStyle Font-Size="8pt" Font-Bold="True" ForeColor="#333333" VerticalAlign="Bottom"></NextPrevStyle>
        
<DayHeaderStyle Font-Size="8pt" Font-Bold="True"></DayHeaderStyle>
        
<SelectedDayStyle ForeColor="White" BackColor="#333399"></SelectedDayStyle>
        
<TitleStyle Font-Size="12pt" Font-Bold="True" BorderWidth="4px" ForeColor="#333399" BorderColor="Black"
            BackColor
="White"></TitleStyle>
        
<OtherMonthDayStyle ForeColor="#999999"></OtherMonthDayStyle>
    
</asp:calendar>
</asp:Panel><BR>
<script>

</script>

后台代码:

namespace purchaseorders
{
    
using System;
    
using System.Data;
    
using System.Drawing;
    
using System.Web;
    
using System.Web.UI.WebControls;
    
using System.Web.UI.HtmlControls;

    
/// <summary>
    
///        Summary description for ctlCalendar.
    
/// </summary>

    public class ctlCalendar : System.Web.UI.UserControl
    
{
        
protected System.Web.UI.WebControls.TextBox TextBox1;
        
protected System.Web.UI.WebControls.Panel pnlCalendar;
        
protected System.Web.UI.HtmlControls.HtmlInputButton Button1;
        
protected System.Web.UI.WebControls.Calendar Calendar1;

        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
if (!Page.IsPostBack)
            
{
                
this.TextBox1.Text = System.DateTime.Now.ToShortDateString();
                
this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION: absolute");
            }

            
else
            
{
                
string id = Page.Request.Form["__EVENTTARGET"].Substring(0,Page.Request.Form["__EVENTTARGET"].IndexOf(":"));
                
if (id != this.ID) 
                
{
                    
this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION: absolute");
                }

                
else
                
{
                    
this.pnlCalendar.Attributes.Add("style","POSITION: absolute");
                }


            }

            Page.RegisterClientScriptBlock(
"Script_Panel" + this.ID, "<script> function On"+this.ID+"Click() {  if("+this.ID+"_pnlCalendar.style.display == \"none\")     "+this.ID+"_pnlCalendar.style.display = \"\";   else    "+this.ID+"_pnlCalendar.style.display = \"none\"; } </script>");            
            
this.Button1.Attributes.Add("OnClick","On"+this.ID+"Click()");
            
        }


        
Web Form Designer generated code

        
private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
        
{
            
this.TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
            
this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION: absolute");
        }


    }

}


posted on 2005-01-04 20:45  痛苦并快乐着  阅读(584)  评论(0)    收藏  举报

导航