简体   繁体   English

如何使用包含验证文本框值的RequiredFieldValidator控件的asp.net创建Web服务器控件

[英]how to create web server control using asp.net that contain RequiredFieldValidator control that validate textbox value

I want to web server control using asp.net that contain TextBox with RequiredFieldValidator controls. 我想使用asp.net的Web服务器控件,其中包含带有RequiredFieldValidator控件的TextBox。 i have tried but validation control not work. 我已经尝试过,但验证控制无法正常工作。

please help me thanks in advance. 请事先帮助我。

    protected override void RenderContents(HtmlTextWriter output)
    {
        Panel mypanel = new Panel();
        TextBox txtName = new TextBox();
        txtName.ID = "txtNameVal";
        txtName.EnableViewState = true;

        RequiredFieldValidator myrqv = new RequiredFieldValidator();
        myrqv.ErrorMessage = "Please enter the value";
        myrqv.EnableViewState = true;
        myrqv.EnableTheming = true;
        myrqv.ClientIDMode = System.Web.UI.ClientIDMode.Inherit;
        myrqv.Display = ValidatorDisplay.Dynamic;
        myrqv.ValidateRequestMode = System.Web.UI.ValidateRequestMode.Inherit;
        myrqv.ViewStateMode = System.Web.UI.ViewStateMode.Inherit;

        myrqv.ControlToValidate = txtName.ID;
        //myrqv.Text = "*";
        txtName.AutoPostBack = false;
        mypanel.Controls.Add(txtName);
        mypanel.Controls.Add(myrqv);


        mypanel.RenderControl(output);

        output.Write("<br/><br/>");
        string mytxt = "<br/>";
        output.Write(mytxt);
        //output.Write(Text);
    }

vilas jadhav 维拉斯·贾达夫

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM