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

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

博客园 - 不可以

Framework 各版本比较对 用xperf查看系统启动过程 在无IIS下用SharpDevelop进行Asp.net 开发 从程序集中读取流信息 fiddler 学习笔记 .net 拷贝方法 IPhone 应用程序管理 Subversion配置安装 使用Windows Live Writer写博客 xml操作学习 Oracle学习 windbg学习 在博客园添加Web Live Messenger对话框 java调用C#写的com组件 配置文件加入智能提示(Intellisense)功能 让相同的winform程序只启动一个 用户中心 - 博客园 用户中心 - 博客园 去除左边数字行号工具
可以自由控制fileupload文本框与命令按钮之间的距离
不可以 · 2007-06-22 · via 博客园 - 不可以

目标:可以自由控制fileupload文本框与命令按钮之间的距离
原理:修改生成的html中的input type=file控件的属性,隐藏其中文本框,加上一个文本框,实现变相的上传控件。
其生成的html原代码为:
<input id='uploadText' value=''/>&nbsp;&nbsp;<input onpropertychange="uploadText.value=this.value;" type="file" name="MyUploadFile1" id="MyUploadFile1" style="width:0px;border-width:0" />
其中红色就为其中的关键,相信大家都看的懂吧,我就不再解释了
呵呵(只改了一下显示其实质还是原来的fileupload).

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;

namespace LK.WebControl
{
    /// <summary>
    /// MyUploadFile 的摘要说明
    /// </summary>
    public class MyUploadFile : FileUpload
    {

        public MyUploadFile()
        {
        }

        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Style, "width:0px;border-width:0");
            writer.AddAttribute("onpropertychange", "uploadText.value=this.value;");
            base.AddAttributesToRender(writer);
        }

        #region 属性
        /// <summary>
        /// 文本框与命令按钮的间距
        /// </summary>
        [BrowsableAttribute(true)]
        [DescriptionAttribute("文本框与命令按钮的间距")]
        [CategoryAttribute("外观")]
        public int CellSpace
        {
            get { return _cellSpace; }
            set { _cellSpace = value; }
        }
        private int _cellSpace = 0;

        [BrowsableAttribute(true)]
        [DescriptionAttribute("文本框的样式")]
        [CategoryAttribute("外观")]
        public string TextCss
        {
            get { return _textCss; }
            set { _textCss = value; }
        }
        private string _textCss;

        [BrowsableAttribute(true)]
        [DescriptionAttribute("文本框的宽度")]
        [CategoryAttribute("外观")]
        public string TextWidth
        {
            get { return _textWidth; }
            set { _textWidth = value; }
        }
        private string _textWidth;

        [BrowsableAttribute(true)]
        [DescriptionAttribute("文本框的高度")]
        [CategoryAttribute("外观")]
        public string TextHeight
        {
            get { return _textHeight; }
            set { _textHeight = value; }
        }
        private string _textHeight;
        #endregion

        public override void RenderControl(HtmlTextWriter writer)
        {
            if (Visible)
            {
                string strStyle = "style='{0}'";
                string styleValue = "";
                writer.Write("<input id='uploadText' value='' ");
                if (!string.IsNullOrEmpty(_textWidth))
                    styleValue+= "width:"+_textWidth+"px;";
                if (!string.IsNullOrEmpty(_textHeight))
                    styleValue +="height:"+_textHeight+ "px;";
                if (!string.IsNullOrEmpty(_textCss))
                    writer.Write(" class='" + _textCss + "' ");
                if (!string.IsNullOrEmpty(styleValue))
                    styleValue = string.Format(strStyle,styleValue);
                writer.Write(styleValue );
                writer.Write(" />");
                for (int i = 0; i < _cellSpace; i++)
                {
                    writer.Write("&nbsp;");
                }
            }
            base.RenderControl(writer);
        }
    }
}