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

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 七思软件

基于.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;
  }


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