首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

日历控件的两个有关问题

2012-01-02 
日历控件的两个问题代码:usingSystemusingSystem.DatausingSystem.DrawingusingSystem.WebusingSystem

日历控件的两个问题
代码:
using   System;
using   System.Data;
using   System.Drawing;
using   System.Web;
using   System.Web.UI.WebControls;
using   System.Web.UI.HtmlControls;

///   <summary>  
///   </summary>
public   class   Calendar   :   System.Web.UI.UserControl
{
protected   System.Web.UI.WebControls.Calendar   Calendar1;
protected   System.Web.UI.WebControls.Panel   pnlCalendar;
protected   System.Web.UI.WebControls.TextBox   TextBoxDate;
protected   System.Web.UI.HtmlControls.HtmlInputButton   Button1;

private   void   Page_Load(object   sender,   System.EventArgs   e)
{
if   (!Page.IsPostBack)
{
this.TextBoxDate.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() ");
InitializeComponente();

//   在這裡放置使用者程式碼以初始化網頁
}

#region   Web   Form   設計工具產生的程式碼
override   protected   void   OnInit(EventArgs   e)
{
//
//   CODEGEN:   此為   ASP.NET   Web   Form   設計工具所需的呼叫。
//
InitializeComponent();
base.OnInit(e);
}

///   <summary>
///此為設計工具支援所必須的方法   -   請勿使用程式碼編輯器修改
///這個方法的內容。
///   </summary>
private   void   InitializeComponent()
{
this.Calendar1.SelectionChanged   +=   new   System.EventHandler(this.Calendar1_SelectionChanged);
this.Load   +=   new   System.EventHandler(this.Page_Load);

}
#endregion
//
//override   protected   void   OnInit(EventArgs   e)
//{
////  
////
//InitializeComponent();
//base.OnInit(e);
//}


private   void   InitializeComponente()
{
this.Calendar1.SelectionChanged   +=   new   System.EventHandler(this.Calendar1_SelectionChanged);
this.Load   +=   new   System.EventHandler(this.Page_Load);

}


private   void   Calendar1_SelectionChanged(object   sender,   System.EventArgs   e)


{
this.TextBoxDate.Text   =   Calendar1.SelectedDate.ToShortDateString();
this.pnlCalendar.Attributes.Add( "style ", "DISPLAY:   none;   POSITION:   absolute ");

}
}

1,怎么在外aspx中调用这里的TextBox的值?
2,当我选择日期后,他会刷新整个页面,如何不让它刷新,看代码。。。

[解决办法]
1、可以使用跨页提交把值传给另一页,但一般都在本页内提交
2、如果要不刷新,只能使用ajax.net中的那个日历控件或者使用第三方控件,比如梅花雪的控件

热点排行