Click here to Skip to main content
15,886,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 : =

C#
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......
Posted
Updated 1-Apr-10 2:31am
v5

1 solution

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?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900