读书人

日历控件的两个有关问题

发布时间: 2012-01-02 22:40:04 作者: rapoo

日历控件的两个问题
代码:
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中的那个日历控件或者使用第三方控件,比如梅花雪的控件

读书人网 >asp.net

热点推荐