如何在自定义控件中的按钮单击事件上设置自定义控件文本框的值 [英] how to set value of custom control textbox on button click event in custom control
本文介绍了如何在自定义控件中的按钮单击事件上设置自定义控件文本框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建自定义Web控件(文本框),它只允许文本框中的整数数据类型。在按钮(简单的
asp按钮)提交事件如果文本框中没有数据,自定义控件应该设置TextBox1.Text = 0,这就是我想要的。这是我写的代码。
我检查了几个事件或方法,但是在btnA_click事件后它们被解雇了。我有点新手
。我错过的任何事件或方法?任何建议都被接受。在此先感谢...
public class MasIntTextBox : TextBox
{
private RequiredFieldValidator req;
private RegularExpressionValidator regex;
public string ValGrp { get; set; }
public string IsRequired { get; set; }
protected override void OnInit(EventArgs e)
{
//this.CssClass = "inp-form";
if (IsRequired == "true" || IsRequired == "yes")
{
req = new RequiredFieldValidator();
req.ControlToValidate = this.ID;
req.ErrorMessage = "Enter Numeric Value";
req.Display = ValidatorDisplay.Dynamic;
if (!string.IsNullOrEmpty(ValGrp))
req.ValidationGroup = ValGrp;
Controls.Add(req);
}
regex = new RegularExpressionValidator();
regex.ControlToValidate = this.ID;
regex.ErrorMessage = "Numeric Value Only";
regex.Display = ValidatorDisplay.Dynamic;
regex.ValidationExpression = "^\\d+(\\.\\d+)?$";
if (!string.IsNullOrEmpty(ValGrp))
regex.ValidationGroup = ValGrp;
Controls.Add(regex);
//base.OnInit(e);
}
protected override void Render(HtmlTextWriter w)
{
base.Render(w);
if (IsRequired == "true" || IsRequired == "yes")
req.RenderControl(w);
regex.RenderControl(w);
}
}
我想在此课程中为此要求编写代码。
感谢先进...
Anish
推荐答案
嗨Anish _ 4 _朋友,
Hi Anish _ 4 _ Friends,
欢迎来到MSDN论坛支持。
Welcome to MSDN Forum Support.
你在说什么是使用ASP.NET控件来自定义自定义控件。 Y 您需要将其发布在专门的ASP.Net论坛中 http:/ /forums.asp.net for
更有效的回复,您可以联系ASP.NET专家。
What you are talking about is using ASP.NET control to customize custom control. You'll need to post it in the dedicated ASP.Net Forum http://forums.asp.net for more efficient responses, where you can contact ASP.NET experts.
此致,
Jason Wang
Jason Wang
这篇关于如何在自定义控件中的按钮单击事件上设置自定义控件文本框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文