惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
AI
AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
H
Help Net Security
Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
L
LINUX DO - 最新话题
A
Arctic Wolf
博客园_首页
S
Securelist
S
Secure Thoughts
Google DeepMind News
Google DeepMind News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Cyberwarzone
Cyberwarzone
小众软件
小众软件
T
Threatpost
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Blog — PlanetScale
Blog — PlanetScale
N
News and Events Feed by Topic
NISL@THU
NISL@THU
Forbes - Security
Forbes - Security
博客园 - 聂微东
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
H
Heimdal Security Blog
罗磊的独立博客
S
Security @ Cisco Blogs
B
Blog
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
Hacker News - Newest:
Hacker News - Newest: "LLM"
I
Intezer
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
The Cloudflare Blog
S
Schneier on Security
月光博客
月光博客
L
LINUX DO - 热门话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

博客园 - 七思软件

基于.Net的架构设计之七 基于.Net架构设计之六 基于.Net的架构设计之五 基于.Net架构设计之四 基于.Net架构设计之三 基于.Net架构设计之二 基于.Net的架构设计之一 Microsoft.Visual.Studio.2005.Team.System 面象asp.net2.0的MasterControls控件 aspx页面中标题单点解决方案 求助,web应用程序中的进程线程控制 (The 'url' property had a malformed URL)求助 - 七思软件 Asp.net 2.0功能体验,细节之Web控件(一) 隐藏控件 Asp.net 2.0功能体验,总体设计思想 Asp.net 2.0功能体验,欢迎光临指导 C#中泛型求助 C#2.0中可空类型 迎接.Net2.0 我只是一只碌碌无为的工蚁 : (
论Web控件开发 - 完美上传下载控件“新”(五)
七思软件 · 2005-01-22 · via 博客园 - 七思软件

服务器端事件和客户端事件介绍完后下面介绍控件的生成,

//输出图片按钮之间的空白图片
  protected virtual void WriteSpace(HtmlTextWriter writer)
  
{
   writer.AddAttribute(HtmlTextWriterAttribute.Src, DefaultImagePath
+"HSpace2.gif");
   writer.RenderBeginTag(HtmlTextWriterTag.Img);
   writer.RenderEndTag();
  }

 
  
protected override void Render(HtmlTextWriter writer)
  
{
//输出具有一行两个cell的表格其中第一个cell放置htmlinputfile,第二个cell放upload/delete/download/inputhidden按钮

   writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, 
"0");
   writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, 
"0");
   
if(this.Width!=Unit.Empty)
    writer.AddAttribute(HtmlTextWriterAttribute.Width, Width.ToString());
   writer.AddAttribute(HtmlTextWriterAttribute.Border, 
"0");
   
//table
   writer.RenderBeginTag(HtmlTextWriterTag.Table);
   writer.RenderBeginTag(HtmlTextWriterTag.Tr);
   
//cell1
//使第二cell的按钮充满单元格,由于inputfile的宽度为100%这样通过设置最外层table的width可以精确控制控件的宽度
   writer.AddAttribute(HtmlTextWriterAttribute.Width, "98%");
   writer.RenderBeginTag(HtmlTextWriterTag.Td);
//定义inputfile的客户端id
   this.FileUpload.Attributes.Add("id",this.ClientID+"__file");
   
this.FileUpload.RenderControl(writer);
   writer.RenderEndTag();
   
//cell2,为了使后三个按钮不换行输出nowrap属性
   writer.AddAttribute(HtmlTextWriterAttribute.Nowrap,"Yes");
   writer.RenderBeginTag(HtmlTextWriterTag.Td);
   
//hiden input file
   this.TxtFileName.Attributes.Add("id",this.ClientID);
   
this.TxtFileName.RenderControl(writer);
   
//upload btn
   WriteSpace(writer);
//绑定upload客户端事件
   string onClick = this.BtnUpLoad.Attributes["onclick"]==null?string.Empty:this.BtnUpLoad.Attributes["onclick"];
   
this.BtnUpLoad.Attributes["onclick"= string.Format("if(!({0}_obj.CheckUpload())) return false;",this.ClientID) + onClick;
   
this.BtnUpLoad.RenderControl(writer);

   
//delete btn
   if(this.AllowDelete) WriteSpace(writer); 
//绑定delete客户端事件
   onClick = (this.BtnDelete.Attributes["onclick"]==null)?string.Empty:this.BtnDelete.Attributes["onclick"];
   
this.BtnDelete.Attributes["onclick"= string.Format("if(!({0}_obj.CheckDelete())) return false;",this.ClientID)+ onClick;
   
this.BtnDelete.RenderControl(writer);


   
//download btn
   WriteSpace(writer);
//绑定download客户端事件
   this.BtnDownload.Attributes["onclick"]=string.Format("if(!({0}_obj.CheckDownload(this))) return false;",this.ClientID);
   
this.BtnDownload.RenderControl(writer);
   writer.RenderEndTag();
   
   writer.RenderEndTag();
   writer.RenderEndTag();
  }

  
  
protected override void CreateChildControls()
  
{
   
this.Controls.Clear();
   
//button hidden ctl0首先创建inputhidden因为其它控件会用到些控件.
   this._txtFileName = new System.Web.UI.HtmlControls.HtmlInputHidden();
   
this.Controls.Add(this._txtFileName);

   
//file upload ctl1创建上传文件控件
   this._fileUpload = new System.Web.UI.HtmlControls.HtmlInputFile();
//充满第一个单元格
   this._fileUpload.Style.Add("WIDTH","100%");
//应用样式
   if(this.CSS!=string.Empty)
    
this._fileUpload.Attributes.Add("class",this.CSS);
   
this.Controls.Add(this._fileUpload);

   
//button upload上传控件
   this._btnUpLoad = new ImageButton();
   
this._btnUpLoad.ImageUrl = this.UploadImg;
   
if(this.UploadFileNameType != FileNameType.AutoGenerate)
    
this._btnUpLoad.EnableWarning = true;
   
else
    
this._btnUpLoad.EnableWarning = false;
   
this._btnUpLoad.AlternateText = this.UploadAlt;
   
this._btnUpLoad.WarningMessage = "如果文件已经存在将被覆盖,确定吗?";
   
this._btnUpLoad.CausesValidation = false;
//绑定上传事件
   this._btnUpLoad.Click += new ImageClickEventHandler(Upload_Clicked);
   
this.Controls.Add(this._btnUpLoad);

   
//button delete创建删除按钮
   this._btnDelete = new ImageButton();
   
this._btnDelete.ImageUrl = this.DeleteImg;
   
this._btnDelete.EnableWarning = true;
   
this._btnDelete.AlternateText = this.DeleteAlt;
   
this._btnDelete.WarningMessage = "确定要删除吗?";
//不触发验证
   this._btnDelete.CausesValidation = false;
//绑定删除事件
   this._btnDelete.Click +=new ImageClickEventHandler(Delete_Clicked);
   
if(!this.AllowDelete)
    
this._btnDelete.Visible = false;
   
this.Controls.Add(this._btnDelete);

   
//button download
   this._btnDownload = new HyperLink();
   
this._btnDownload.Style.Add("cusor","hand");
   
this._btnDownload.ImageUrl = this.DownloadImg;
   
this._btnDownload.ToolTip = this.DownloadAlt;
   
this._btnDownload.NavigateUrl = this.FullFileName;
   
this._btnDownload.Target = "_blank";
   
this._btnDownload.Text = "download";

   
this.Controls.Add(this._btnDownload);


//子控件创建成功
   ChildControlsCreated = true;
  }


最后是视图状态的相关函数,可以参考我以前的文章在此只是把代码列下