关于自定义控件--这个自定义控件问题在哪里?
hz890 2007-09-05 09:17:27 我将代码贴出,如下:
控件代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
namespace WebCalenderControl
{
public class WebCustomControl : WebControl
{
public enum EnableContent
{
True,
False
}
private DateTime _value;
private EnableContent _enable;
private string _width;
public DateTime Date
{
get
{
return this._value;
}
set
{
this._value = value;
}
}
public EnableContent Enable
{
get
{
return this._enable;
}
set
{
this._enable = value;
}
}
public new string Width
{
get
{
return this._width;
}
set
{
this._width = value;
}
}
public void Calendar()
{
this._value = new DateTime(0x76c, 1, 1);
this._width = "80px";
}
protected override void RenderContents(HtmlTextWriter output)
{
//output.Write(Text);
}
protected override void Render(HtmlTextWriter output)
{
DateTime time = new DateTime(0x76c, 1, 1);
string text = "";
if (this._value <= time)
{
text = "";
}
else
{
string text2 = this._value.Month.ToString().PadLeft(2, '0');
string text3 = this._value.Day.ToString().PadLeft(2, '0');
string text4 = this._value.Year.ToString().PadLeft(4, '0');
text = text4 + "-" + text2 + "-" + text3;
}
output.Write("<input style='width:" + this._width + ";' name='" + this.UniqueID + "' type=text value='" + text + "' readonly='true' />");
output.Write("<input " + ((this.Enable == EnableContent.False) ? "disabled" : "") + " style='width:23px;height:23px;background-image:url(" + GetResource(this, "WebCalenderControl.CalendarControl.calendar.gif") + ");' type=button ID='btnSave' OnClick=\"javascript:Pop_calc('" + this.UniqueID + "','" + GetResource(this, "WebCalenderControl.CalendarControl.Calendar.htm") + "') \"> ");
}
public void RaisePostDataChangedEvent()
{
}
public void RaisePostBackEvent(string eventArgument)
{
if (((TextBox)this.Controls[1]).Text != "")
{
this._value = DateTime.Parse(((TextBox)this.Controls[1]).Text);
}
this._width = ((TextBox)this.Controls[1]).Width.ToString();
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (!this.Page.ClientScript.IsClientScriptIncludeRegistered("WebPage_PopupParts"))
{
this.Page.ClientScript.RegisterClientScriptInclude("WebPage_PopupParts", GetResource(this, "WebCalenderControl.CalendarControl.pg.js"));
}
}
public bool LoadPostData(string postDataKey, NameValueCollection values)
{
if ((values[this.UniqueID] != null) && (values[this.UniqueID] != ""))
{
this._value = DateTime.Parse(values[this.UniqueID]);
}
return false;
}
public static string GetResource(Control Owner, string ResourceName)
{
return Owner.Page.ClientScript.GetWebResourceUrl(Owner.GetType(), ResourceName);
}
}
}