可以自由控制fileupload文本框与命令按钮之间的距离
2007-06-22 12:57
861 查看
目标:可以自由控制fileupload文本框与命令按钮之间的距离
原理:修改生成的html中的input type=file控件的属性,隐藏其中文本框,加上一个文本框,实现变相的上传控件。
其生成的html原代码为:
<input id='uploadText' value=''/> <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(" ");
}
}
base.RenderControl(writer);
}
}
}
原理:修改生成的html中的input type=file控件的属性,隐藏其中文本框,加上一个文本框,实现变相的上传控件。
其生成的html原代码为:
<input id='uploadText' value=''/> <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(" ");
}
}
base.RenderControl(writer);
}
}
}
相关文章推荐
- latex 表格如何精细控制行高,行距,行与行之间的距离
- latex 表格如何精细控制行高,行距,行与行之间的距离
- linux的scp命令可以在linux服务器之间复制文件和目录
- ASPxGridView-根据记录值来控制命令按钮(CommandButton)或子表命令列(CommandColumn)的显示与可用
- abap报表中(ALV或者普通屏幕的定制控制中)如何让列可以使用求和按钮
- 使用js实现按钮控制文本框加1减1应用于小时+分钟
- 初学Qt之--用按钮控制文本框显示按钮上的字符
- Android开发 通过2个按钮来控制一个文本框的背景颜色
- 窗体和命令按钮、标签、文本框控件的常用属性
- 改装Juploader上传组件,使其可以控制自由上传
- 经典的图片无缝滚动,点击向上向下按钮还可以控制方向
- 自由控制TabLayout和ViewPager结合使用时是否可以点击和滑动
- div滚动条,可以自由的给滚动条定义背景,上下按钮,当然不仅仅是颜色,连图片当背景也可以。
- Android开关按钮ToggleButton的使用,可以实现密码框和文本框的切换
- 命令按钮、标签框、文本框
- OA系统中根据文本框按钮控制执行路径和人员加锁和置灰
- jsp页面使用js控制文本框只读,并且按下backspace删除按钮后停在原页面
- 创建一个CPoint类,代表平面直角坐标系中的点,创建构造函数和运算符重载函数, 运算符重载为类重载(非友元重载),可以实现计算两个点之间的距离。可以根据需要 加入自己的成员变量或成员函数
- 窗口上提供四个文本框和一个按钮,幼儿可以在前三个文本框中输入两个运算数和运算符号,当点击按钮时在第四个文本框中显示结果。
- js实现按钮控制文本框加1减1,应用于小时+分钟