I some how manage to find the Clue for my Problem But again its not Working
when i dragged the Control It shows error Please Check the Following Code
and Correct me
public class RequiredTextBox : TextBox {
private RequiredFieldValidator req;
public string InvalidMessage;
public string ClientScript="true";
protected override void OnInit(EventArgs e) {
req = new RequiredFieldValidator();
req.ControlToValidate = this.ID;
req.ErrorMessage = this.InvalidMessage;
req.EnableClientScript = (this.ClientScript.ToLower()!="false");
Controls.Add(req);
}
protected override void Render(HtmlTextWriter w) {
base.Render(w);
req.RenderControl(w);
}
2009/8/11 Maddy <[email protected]>
> The Below snippet is my code for TextBox Float validation(its working fine)
>
>
> public class textboxFloat : System.Web.UI.WebControls.TextBox
> {
> private const String CHECK_float_NAME = "floatValidate";
> protected override void OnPreRender(System.EventArgs e)
> {
> StringBuilder clientScript = new StringBuilder();
> base.OnPreRender(e);
> clientScript.Append("<script language='javascript'>");
> clientScript.Append("function " + CHECK_float_NAME + "()");
> clientScript.Append("{");
> clientScript.Append("if ((event.keyCode < 46) || (event.keyCode > 57) ||
> (event.keyCode==47))");
> clientScript.Append("event.returnValue = false;");
> clientScript.Append("}");
> clientScript.Append("</script>\r");
> Page.RegisterClientScriptBlock(CHECK_float_NAME,
> clientScript.ToString());
> }
> protected override void
> AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
> {
> base.AddAttributesToRender(writer);
>
> writer.AddAttribute("onkeypress", "return " + CHECK_float_NAME + "();");
> }
> }
> My Doubt is How to add Regular expression validators to my CS file of the
> Custom Control Textbox Which ll validate EMAIL Address.
>
> *Please Let me Know your suggestions*
>
> --
> Thanks in advance
> Sarvesh
>
--
Sarvesh