关于自定义控件--这个自定义控件问题在哪里?

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);
}
}

}
...全文
118 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hz890 2007-09-06
  • 打赏
  • 举报
回复
求各位帮忙了!

重点帮我看一下这几块代码,我想问题应该在这里。

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 static string GetResource(Control Owner, string ResourceName)
{
return Owner.Page.ClientScript.GetWebResourceUrl(Owner.GetType(), ResourceName);
}


[assembly: WebResource("WebCalenderControl.CalendarControl.calendar.gif", "image/gif")]
[assembly: WebResource("WebCalenderControl.CalendarControl.Calendar.js", "application/x-javascript")]
[assembly: WebResource("WebCalenderControl.CalendarControl.pg.js", "application/x-javascript")]
hz890 2007-09-05
  • 打赏
  • 举报
回复
前几天去网上找过,基本上是什么关于微调控件的,按上面讲的做了一下,没有效果!
真相重于对错 2007-09-05
  • 打赏
  • 举报
回复
大致看看,代码太长没时间看。
hz890 2007-09-05
  • 打赏
  • 举报
回复
估计错误是由于资源未能正确注册到WebResource中造成的,我搞了3天也未能解决,急请帮助!
hz890 2007-09-05
  • 打赏
  • 举报
回复
问题:
自定义的日期控件在浏览器中出现JavaScript错误:必须要有对象
页面的HTML代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
派車管理系統
</title><link rel="Stylesheet" href="../Skin/Css/IcaStyle.css" /><link href="../App_Themes/SkinFile/IcaStyle.css" type="text/css" rel="stylesheet" /></head>
<body class="mainBody">
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjA4NzIyNzA0Ng9kFgICAw9kFhACDw8PFgIeCFJlYWRPbmx5Z2RkAhMPDxYCHwBnZGQCFw8PFgIfAGdkZAIZDw8WAh8AZ2RkAhsPDxYCHwBnZGQCHQ8PFgIfAGdkZAIhDw8WAh8AZ2RkAicPDxYCHwBnZGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgYFCEJ1dFF1ZXJ5BQZCdXROZXcFCUJ1dFVwZGF0ZQUHQnV0U2F2ZQUGQnV0RGVsBQtCdXRUcmFuc2Zlckzvl62lpPfg4u7ZKy0vsKvW+67i" />
</div>


<script src="/AdmSystem/WebResource.axd?d=QgIpZBF7bCunxwpo7_J2iLkwa3QGkmUNlmEl3Zrz1bXbkzT__ozakwl7W9VydTWWudVkzZAMdHD7mVhFgxer8Q2&t=633245360840635882" type="text/javascript"></script>
<center>
<span id="Label1" class="menuTitle" style="display:inline-block;width:90%;">ICHIA訪客管理登記界面</span><br />
<br />
<table width="90%">
<tr><td align="left">
<input type="image" name="ButQuery" id="ButQuery" src="../Skin/Img/query.gif" style="border-width:0px;" />
<input type="image" name="ButNew" id="ButNew" src="../Skin/Img/new.gif" style="border-width:0px;" />
<input type="image" name="ButUpdate" id="ButUpdate" src="../Skin/Img/update.gif" style="border-width:0px;" />
<input type="image" name="ButSave" id="ButSave" src="../Skin/Img/save.gif" style="border-width:0px;" />
<input type="image" name="ButDel" id="ButDel" src="../Skin/Img/del.gif" style="border-width:0px;" />
<input type="image" name="ButTransfer" id="ButTransfer" src="../Skin/Img/transfer.gif" style="border-width:0px;" />
</td></tr>
</table>
<table width="90%" border="1" style="">
<tr>
<td style="width:8%" align="left">來訪者姓名:</td>
<td style="width:20%" align="left">
<input name="strVisitName" type="text" readonly="readonly" id="strVisitName" style="color:Black;font-family:Arial;font-size:12px;" />
</td>
<td style="width:8%" align="left">單位名稱:</td>
<td style="width:20%" align="left">
<input name="strDpname" type="text" readonly="readonly" id="strDpname" style="color:Black;font-family:Arial;font-size:12px;width:61%;" />
</td>
</tr>
<tr>
<td align="left">預約時間:</td>
<td align="left" >
<input style='width:;' name='strBookTime' type=text value='' readonly='true' /><input style='width:23px;height:23px;background-image:url(/AdmSystem/WebResource.axd?d=QgIpZBF7bCunxwpo7_J2iLkwa3QGkmUNlmEl3Zrz1bXbkzT__ozakwl7W9VydTWWZ51yX1VF3gTVt6ZUi91Zz2_hsU7y8krCbHZa4RXn-fs1&t=633245360840635882);' type=button ID='btnSave' OnClick="javascript:Pop_calc('strBookTime','/AdmSystem/WebResource.axd?d=QgIpZBF7bCunxwpo7_J2iLkwa3QGkmUNlmEl3Zrz1bXbkzT__ozakwl7W9VydTWWT8oDsxFYG6whZWnD_CidImnjx73uM8PmaOJpSl29-kY1&t=633245360840635882') ">
</td>
<td align="left">聯繫方式:</td>
<td align="left">
<input name="strContactWay" type="text" readonly="readonly" id="strContactWay" style="color:Black;font-family:Arial;font-size:12px;width:61%;" />
</td>
</tr>
<tr>
<td align="left">來訪人數:</td>
<td align="left">
<input name="strVisitNum" type="text" readonly="readonly" id="strVisitNum" style="color:Black;font-family:Arial;font-size:12px;" />
</td>
<td align="left">來訪事由:</td>
<td align="left">
<input name="strVisitReason" type="text" readonly="readonly" id="strVisitReason" style="color:Black;font-family:Arial;font-size:12px;width:61%;" />
</td>
</tr>
<tr>
<td align="left">備註:</td>
<td colspan="3" align="left">
<input name="strRemark" type="text" readonly="readonly" id="strRemark" style="color:Black;font-family:Arial;font-size:12px;width:88%;" />
</td>
</tr>
</table>
<span id="Label2">受訪人員信息</span>
<table width="90%" border="1">
<tr>
<td align="left">受訪人工號:</td>
<td colspan="5" align="left">
<input name="strResEmployee" type="text" readonly="readonly" id="strResEmployee" style="color:Black;font-family:Arial;font-size:12px;" /></td>
</tr>
<tr>
<td align="left">受訪人姓名:</td>
<td align="left">
<input name="strResName" type="text" id="strResName" style="color:Black;font-family:Arial;font-size:12px;" /></td>
<td align="left">分機號碼:</td>
<td align="left">
<input name="strResExt" type="text" id="strResExt" style="color:Black;font-family:Arial;font-size:12px;" /></td>
<td align="left">短號:</td>
<td align="left">
<input name="strResCornet" type="text" readonly="readonly" id="strResCornet" style="color:Black;font-family:Arial;font-size:12px;" /></td>
</tr>
<tr>
<td align="left">事業處:</td>
<td align="left">
<input name="strResBu" type="text" id="strResBu" style="color:Black;font-family:Arial;font-size:12px;" /></td>
<td align="left">部門代號:</td>
<td align="left">
<input name="strResDpno" type="text" id="strResDpno" style="color:Black;font-family:Arial;font-size:12px;" /></td>
<td align="left">部門名稱:</td>
<td align="left">
<input name="strResDpname" type="text" id="strResDpname" style="color:Black;font-family:Arial;font-size:12px;" /></td>
</tr>
</table>
<span id="Label3" style="font-weight:bold;">經辦人資料核對</span><br />
<table width="90%" border="1">
<tr>
<td align="left">經辦人姓名:</td>
<td align="left">
<input name="strArrEmployee" type="text" id="strArrEmployee" style="color:Black;font-family:Arial;font-size:12px;" />
<span id="strArrName"></span></td>
<td align="left">部門:</td>
<td align="left">
<input name="strArrDpname" type="text" id="strArrDpname" style="color:Black;font-family:Arial;font-size:12px;" /></td>
<td align="left">分機:</td>
<td align="left">
<input name="strArrExt" type="text" id="strArrExt" style="color:Black;font-family:Arial;font-size:12px;" /></td>
</tr>
</table>
</center>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWFwLZ98iNCQL13ZiWAgLd/tKWBAKEr8CXBwKWiPC7BQLd/vbyDwLUsqCVBQLwt5vUDgLfs9yeDALJoLPrBALwt+e7BwKz16vkDQLosPToBwL98OmWDQKJmK+tAQKP5cLvAgKuorOtDgLc5oNoAv77yLAOAqOBvMcJAuCkssQNAtiC7P8OAtjmkscDC0z7J3TFZ4DrPpVR4Ymj/rSjPe0=" />
</div></form>
</body>
</html>
真相重于对错 2007-09-05
  • 打赏
  • 举报
回复
b/s
是无状态的,把所有的属性存放在viewstate, cookie ,session中 ,否则会丢失
hz890 2007-09-05
  • 打赏
  • 举报
回复
AssemblyInfo.cs代码:
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WebCalenderControl")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ichia")]
[assembly: AssemblyProduct("WebCalenderControl")]
[assembly: AssemblyCopyright("Copyright © ichia 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: WebResource("WebCalenderControl.CalendarControl.calendar.gif", "image/gif")]
[assembly: WebResource("WebCalenderControl.CalendarControl.Calendar.js", "application/x-javascript")]
[assembly: WebResource("WebCalenderControl.CalendarControl.pg.js", "application/x-javascript")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("85235fd9-1cdf-4686-b3f5-31d15740b53f")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

62,073

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧