创建自定义文本框控件时出错 [英] Error creating custom Textbox Control

查看:60
本文介绍了创建自定义文本框控件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



正在创建具有布尔属性isRequred的自定义Web控件.在运行时,控件运行正常,没有任何问题.没有任何问题.但是在设计时,它显示了此错误而不是控制...

当我们从设计器的工具箱中拖动控件时.控件不会生成,除了写以下消息来代替控件

创建控件时出错-ExcelTextBox
无法在属性必需"上设置true






代码如下:=

Hi,

am creating a custom web control which have boolean property isRequred. At the runtime the control just works fine without any problem. there is no problem whatsoever. But at the design time it shows this error in place of control ...

When We drag the control from the toolbox in the desiger. the controls does not generates besides it write following message in place of control

Error creating control - ExcelTextBox
true cannot be set on property ''Required''






Code is as below : =

private bool required = false;
private RequiredFieldValidator req = null;

public bool Required
               {
                   get
                   {
                       return this.required;
                   }
                   set
                   {
                       this.required = value;
                   }
               }
protected override void OnInit(EventArgs e)
      {
          Controls.Clear();
          this.ID = base.ID;
          if (Required)
          {
              req = new RequiredFieldValidator();
              req.ID = "rfv" + this.ClientID;
              req.ControlToValidate = this.ClientID;
              req.ValidationGroup = this.ValidationGroup;
              req.ErrorMessage = ErrorMessage;
              req.Text = "*";
              req.EnableClientScript = (this.ClientScript.ToLower() != "false");
              this.Controls.Add(req);
          }

}

protected override void Render(HtmlTextWriter w)
       {
           base.Render(w);
           if (Required)
           {
               req.RenderControl(w);
           }
}



出现错误的原因是什么

请在这方面帮助我......



What is the reason behind getting error

Please help me in this regard......

推荐答案

在哪里-确切地-代码中出现错误,为什么不只是错误?使用验证程序来确保用户输入了什么?
Where - exactly - in the code are you getting the error, and why aren''t you just using a Validtor instead to make sure the user entered something?


这篇关于创建自定义文本框控件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆