各位大虾
小弟想创建一个自定义的 TextBox 控件打包成 dll
控件有 value 属性外,还要有储存客户端jscript语句写入值的另一属性(如 value2)
如何在服务器端取得 value 和 value2 改变后的值
(value 可以由 Text 属性取得,但 value2 实现不了服务器端取值)
请帮帮忙啊
小弟想创建一个自定义的 TextBox 控件打包成 dll
控件有 value 属性外,还要有储存客户端jscript语句写入值的另一属性(如 value2)
如何在服务器端取得 value 和 value2 改变后的值
(value 可以由 Text 属性取得,但 value2 实现不了服务器端取值)
请帮帮忙啊
解决方案 »
- aspx页面出现了一个很搞笑的混乱,难道是VS的bug吗?
- Flash图片如何传参给.net
- TreeView控件中行距和字间距离的设置问题
- linq to sql中遇到的奇怪问题
- 小弟刚学.net有些简单问题请各位帮忙.谢谢!!!!!!!!!
- 大家对.net开发人员在软件公司工作和在网站工作有什么看法?
- 在线等:水晶报表导出EXCEL,在WEB服务器所在机器上没有问题,在别的机器上则调不了
- 百分寻找把水晶报表导成pdf或xls文件的代码
- 一个关于datagrid的难题
- 请问datagrid弹出窗口的问题!搞了好几天了:(,感激!
- 日历控件一显示出来就和其他控件重叠,有什么办法解决?我是初学.
- C#基础问题
并设定一个属性如VALUE2
private void contol_Load(object sender, System.EventArgs e)
{
((TextBox)Controls[1]).Text=this.VALUE2;
} public string VALUE2
{
get
{
return ((TextBox)Controls[1]).Text;
}
set
{
((TextBox)Controls[1]).Text = value;
}
}服务端读取的时候就访问VALUE2这个属性
我定义控件的方法
public class MyControl: System.Web.UI.WebControls.TextBox
{
.......
}
在里面添加了子控件TextBox
protected override void Render(HtmlTextWriter writer)
{
TextBox a = new TextBox();
a.ID = this.ID + "_0";
this.Controls.Add(a);
}
客户端看不到有第二个TextBox啊
Control, INamingContainer
//或许对你有所启发.using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;namespace CustomControls
{
/// <summary>
/// CustomNumeric 的摘要说明。
/// </summary>
public class CustomTextBox:Control, INamingContainer
{
private string cur_id ="txtNum";
public CustomTextBox()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private ValidatorDisplay SetDisplayType; [Description("验证程序的显示方式"),DefaultValue("Static")]
public ValidatorDisplay Display
{
get
{
return this.SetDisplayType;
}
set
{
this.SetDisplayType = value;
this.EnsureChildControls();
}
} /// <summary>
/// 输入长度
/// </summary>
public int MaxLength
{
get
{
if(ViewState["maxLength"]==null)
return 8;
else
return (int)ViewState["maxLength"];
}
set
{
this.ViewState["maxLength"] = value;
}
}
/// <summary>
/// 输入长度
/// </summary>
public int width
{
get
{
if(ViewState["width"]==null)
return 100;
else
return (int)ViewState["width"];
}
set
{
this.ViewState["width"] = value;
}
} public bool Enabled
{
get
{
this.EnsureChildControls();
return ((TextBox)this.Controls[0]).Enabled;
}
set
{
this.EnsureChildControls();
((TextBox)this.Controls[0]).Enabled = value;
}
} [Description("文本值"),DefaultValue(0)]
public string Text
{
get
{
this.EnsureChildControls();
return ((TextBox)this.Controls[0]).Text;
}
set
{
this.EnsureChildControls();
((TextBox)this.Controls[0]).Text = value;
}
} [Description("控件ID")]
public override string ID
{
get
{
return cur_id;
}
set
{
cur_id = value;
this.EnsureChildControls();
}
} [Description("错误信息")]
public string ValidationExpression
{
get
{
this.EnsureChildControls();
return ((RegularExpressionValidator)this.Controls[1]).ValidationExpression;
}
set
{
this.EnsureChildControls();
((RegularExpressionValidator)this.Controls[1]).ValidationExpression = value;
}
} [Description("用于确定有效性的正则表达式")]
public string ErrorMessage
{
get
{
this.EnsureChildControls();
return ((RegularExpressionValidator)this.Controls[1]).ErrorMessage;
}
set
{
this.EnsureChildControls();
((RegularExpressionValidator)this.Controls[1]).ErrorMessage = value;
}
} protected override void CreateChildControls()
{
TextBox box = new TextBox();
box.Enabled=true;
box.EnableViewState = true;
this.Controls.Add(box);
box.ID = cur_id+box.ClientID;
RegularExpressionValidator rev = new RegularExpressionValidator();
rev.EnableViewState = true;
this.Controls.Add(rev);
rev.ID = cur_id+rev.ClientID; this.PreRender +=new System.EventHandler(this.contol_Load);
}
private void contol_Load(object sender, System.EventArgs e)
{
((RegularExpressionValidator)this.Controls[1]).ValidationExpression = this.ValidationExpression;
((RegularExpressionValidator)this.Controls[1]).ErrorMessage = this.ErrorMessage;
((RegularExpressionValidator)this.Controls[1]).Display = this.Display;
((RegularExpressionValidator)this.Controls[1]).ControlToValidate =((TextBox)this.Controls[0]).ID;
}
}
}