当前位置: 首页>>代码示例>>C#>>正文


C# WebControls.RequiredFieldValidator类代码示例

本文整理汇总了C#中System.Web.UI.WebControls.RequiredFieldValidator的典型用法代码示例。如果您正苦于以下问题:C# RequiredFieldValidator类的具体用法?C# RequiredFieldValidator怎么用?C# RequiredFieldValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RequiredFieldValidator类属于System.Web.UI.WebControls命名空间,在下文中一共展示了RequiredFieldValidator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DynamicTextBox

        public DynamicTextBox(DynamicTextBoxXml xml)
        {
            _textBox = new TextBox();
            _textBox.CausesValidation = false;

            _required = new RequiredFieldValidator();
            _required.Display = ValidatorDisplay.Dynamic;
            _required.EnableClientScript = true;
            _required.Text = "*";
            _required.Enabled = false;
            _required.ClientIDMode = System.Web.UI.ClientIDMode.Static;

            this.Controls.Add(_textBox);
            this.Controls.Add(_required);

            this.ID = xml.Name;
            this.IsRequired = xml.IsRequired;
            this.ErrorMessage = xml.ErrorMessage;
            this.ValidationGroup = xml.ValidationGroup;
            this.MaxLength = xml.MaxLength;
            _textBox.Text = xml.Text;

            this.controlXML = xml;

            this.Visible = xml.Visible;
        }
开发者ID:danilocecilia,项目名称:HulcherProject,代码行数:26,代码来源:DynamicTextBox.cs

示例2: InitializeDataCell

 protected override void InitializeDataCell(DataControlFieldCell cell, DataControlRowState rowState)
 {
     //base.InitializeDataCell(cell, rowState);
     TextBox textBox = new TextBox();
     textBox.ID = this.ControlID;
     textBox.Width = new Unit(GridColumn.Width, UnitType.Pixel);
     if (GridColumn.Size != 0) textBox.MaxLength = GridColumn.Size;
     textBox.DataBinding += new EventHandler(this.textBox_DataBinding);
     base.InitializeDataCell(cell, rowState);
     cell.Controls.Add(textBox);
     CompareValidator vld = new CompareValidator();
     vld.ControlToValidate = textBox.ID;
     vld.ID = textBox.ID + "vld";
     vld.Operator = ValidationCompareOperator.DataTypeCheck;
     vld.ErrorMessage = "не верный формат (2)";
     vld.Text = "! (2)";
     vld.Display = ValidatorDisplay.Dynamic;
     if (GridColumn.Type == typeof(int)) vld.Type = ValidationDataType.Integer;
     if (GridColumn.Type == typeof(decimal)) vld.Type = ValidationDataType.Double;
     if (GridColumn.Type == typeof(string)) vld.Type = ValidationDataType.String;
     cell.Controls.Add(vld);
     if (!GridColumn.AllowNULL)
     {
         RequiredFieldValidator reqvld = new RequiredFieldValidator();
         reqvld.ControlToValidate = textBox.ID;
         reqvld.ID = textBox.ID + "reqvld";
         reqvld.ErrorMessage = "поле не может быть пустым (1)";
         reqvld.Text = "! (1)";
         reqvld.Display = ValidatorDisplay.Dynamic;
         cell.Controls.Add(reqvld);
     }
 }
开发者ID:vahtel65,项目名称:Aspect_loc,代码行数:32,代码来源:TextBoxProductGridField.cs

示例3: DynamicCountableTextBox

        public DynamicCountableTextBox(DynamicCountableTextBoxXml xml)
        {
            _textBox = new CountableTextBox();
            _textBox.CausesValidation = false;

            _required = new RequiredFieldValidator();
            _required.Display = ValidatorDisplay.Dynamic;
            _required.EnableClientScript = true;
            _required.Text = "*";
            _required.Enabled = false;
            _required.ClientIDMode = System.Web.UI.ClientIDMode.Static;

            this.Controls.Add(_textBox);
            this.Controls.Add(_required);

            this.ID = xml.Name;
            this.IsRequired = xml.IsRequired;
            this.ErrorMessage = xml.ErrorMessage;
            this.ValidationGroup = xml.ValidationGroup;

            this.MaxChars = xml.MaxChars;
            this.MaxCharsWarning = xml.MaxCharsWarning;
            this.TextMode = xml.TextMode;
            this.Width = new Unit(xml.Width);
            this.Height = new Unit(xml.Height);
            _textBox.Text = xml.Text;

            this.Visible = xml.Visible;

            this.controlXML = xml;

            this.Style[HtmlTextWriterStyle.Display] = "block";
        }
开发者ID:danilocecilia,项目名称:HulcherProject,代码行数:33,代码来源:DynamicCountableTextBox.cs

示例4: CreateChildControls

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            Label lblQuestion = new Label();
            _ddAnswer = new DropDownList();
            RequiredFieldValidator valQuestion = new RequiredFieldValidator();

            lblQuestion.ID = "lbl" + _question.QuestionGuid.ToString().Replace("-", String.Empty);
            _ddAnswer.ID = "dd" + _question.QuestionGuid.ToString().Replace("-", String.Empty);
            valQuestion.ID = "val" + _question.QuestionGuid.ToString().Replace("-", String.Empty);

            lblQuestion.Text = _question.QuestionText;
            lblQuestion.AssociatedControlID = _ddAnswer.ID;

            valQuestion.ControlToValidate = _ddAnswer.ID;
            valQuestion.Enabled = _question.AnswerIsRequired;

            _ddAnswer.Items.Add(new ListItem(Resources.SurveyResources.DropDownPleaseSelectText, String.Empty));

            foreach (QuestionOption option in _options)
            {
                ListItem li = new ListItem(option.Answer);
                if (li.Value == _answer) li.Selected = true;
                _ddAnswer.Items.Add(li);
            }

            valQuestion.Text = _question.ValidationMessage;

            Controls.Add(lblQuestion);
            Controls.Add(_ddAnswer);
            Controls.Add(valQuestion);
        }
开发者ID:joedavis01,项目名称:mojoportal,代码行数:32,代码来源:DropDownListQuestion.cs

示例5: DynamicDropDownList

        public DynamicDropDownList(DynamicDropDownListXml xml)
        {
            _dropdown = new DropDownList();
            _dropdown.CausesValidation = false;

            _required = new RequiredFieldValidator();
            _required.Display = ValidatorDisplay.Dynamic;
            _required.EnableClientScript = true;
            _required.Text = "*";
            _required.Enabled = false;
            _required.ClientIDMode = System.Web.UI.ClientIDMode.Static;

            this.Controls.Add(_dropdown);
            this.Controls.Add(_required);

            this.ID = xml.Name;
            this.IsRequired = xml.IsRequired;
            this.ErrorMessage = xml.ErrorMessage;
            this.ValidationGroup = xml.ValidationGroup;
            this.FilterId = xml.FilterId;
            if (!string.IsNullOrEmpty(xml.SelectedValue))
            {
                _dropdown.SelectedValue = xml.SelectedValue;
                _selectedValueOnLoad = xml.SelectedValue;
            }

            this.controlXML = xml;

            this.Visible = xml.Visible;
        }
开发者ID:danilocecilia,项目名称:HulcherProject,代码行数:30,代码来源:DynamicDropDownList.cs

示例6: CreateChildControls

        //Override the Create Child Controls event
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            //label for radio button list
            lblTFQuestion = new Label();
            lblTFQuestion.ID = "lblTFQuestion";
            lblTFQuestion.AssociatedControlID = "uxTFQuestion";
            lblTFQuestion.Text = QuestionText;

            //create radio button list
            uxTFQuestion = new RadioButtonList();
            uxTFQuestion.ID = "uxTFQuestion";

            //create validation for radio button list
            reqTFQuestion = new RequiredFieldValidator();
            reqTFQuestion.ID = "reqTFQuestion";
            reqTFQuestion.Display = ValidatorDisplay.Dynamic;
            reqTFQuestion.Text = "*";
            reqTFQuestion.ControlToValidate = "uxTFQuestion";
            reqTFQuestion.ErrorMessage = "No radio selection";

            //create and add list items true and false
            ListItem listTrue = new ListItem("true", "true");
            ListItem listFalse = new ListItem("False", "False");
            uxTFQuestion.Items.Add(listTrue);
            uxTFQuestion.Items.Add(listFalse);

            //add label, radio button list and validator to controls
            Controls.Add(lblTFQuestion);
            Controls.Add(uxTFQuestion);
            Controls.Add(reqTFQuestion);
        }
开发者ID:Deliv3rat0r,项目名称:CST465,代码行数:34,代码来源:TrueFalseQuestion.cs

示例7: RockDropDownList

 /// <summary>
 /// Initializes a new instance of the <see cref="RockDropDownList" /> class.
 /// </summary>
 public RockDropDownList()
 {
     RequiredFieldValidator = new RequiredFieldValidator();
     RequiredFieldValidator.ValidationGroup = this.ValidationGroup;
     HelpBlock = new HelpBlock();
     WarningBlock = new WarningBlock();
 }
开发者ID:NewSpring,项目名称:Rock,代码行数:10,代码来源:RockDropDownList.cs

示例8: CreateChildControls

        protected override void CreateChildControls()
        {
            //EnsureChildControls();
            base.CreateChildControls();
            Label lblQuestion = new Label();
            //TextBox txtQuestion = new TextBox();
            RequiredFieldValidator valQuestion = new RequiredFieldValidator();
            _txtAnswer = new TextBox();
            _txtAnswer.Text = _answer;

            lblQuestion.ID = "lbl" + _question.QuestionGuid.ToString().Replace("-", String.Empty);
            _txtAnswer.ID = "txt" + _question.QuestionGuid.ToString().Replace("-", String.Empty);
            valQuestion.ID = "val" + _question.QuestionGuid.ToString().Replace("-", String.Empty);

            lblQuestion.Text = _question.QuestionText;
            lblQuestion.AssociatedControlID = _txtAnswer.ID;

            valQuestion.ControlToValidate = _txtAnswer.ID;
            valQuestion.Enabled = _question.AnswerIsRequired;

            valQuestion.Text = _question.ValidationMessage;

            Controls.Add(lblQuestion);
            Controls.Add(_txtAnswer);
            Controls.Add(valQuestion);
        }
开发者ID:joedavis01,项目名称:mojoportal,代码行数:26,代码来源:TextBoxQuestion.cs

示例9: DynamicRadioButtonList

        public DynamicRadioButtonList()
        {
            controlXML = new DynamicRadioButtonListXml();

            _tbControls = new Table();
            _trControls = new TableRow();
            _tdLabel = new TableCell();
            _tdControl = new TableCell();
            _tdRequired = new TableCell();
            _trControls.Cells.Add(_tdLabel);
            _trControls.Cells.Add(_tdControl);
            _trControls.Cells.Add(_tdRequired);
            _tbControls.Rows.Add(_trControls);

            _radioButtonList = new RadioButtonList();
            _radioButtonList.CausesValidation = false;
            _radioButtonList.RepeatDirection = RepeatDirection.Horizontal;

            _required = new RequiredFieldValidator();
            _required.Display = ValidatorDisplay.Dynamic;
            _required.EnableClientScript = true;
            _required.Text = "*";
            _required.Enabled = false;

            _tdControl.Controls.Add(_radioButtonList);
            _tdRequired.Controls.Add(_required);
            this.Controls.Add(_tbControls);
        }
开发者ID:danilocecilia,项目名称:HulcherProject,代码行数:28,代码来源:DynamicRadioButtonList.cs

示例10: TextControl

		public TextControl(TextQuestion question)
		{
			_tb = new TextBox {CssClass = "alternative", ID = "q" + question.ID};

			if (question.Rows > 1)
			{
				_tb.TextMode = TextBoxMode.MultiLine;
				_tb.Rows = question.Rows;
			}

			if (question.Columns.HasValue)
			{
				_tb.Columns = question.Columns.Value;
			}

			_l = new Label {CssClass = "label", Text = question.Title, AssociatedControlID = _tb.ID};

			Debug.Assert(Controls != null, "Controls != null");
			Controls.Add(_l);
			Controls.Add(_tb);

			if (!question.Required) return;

			_rfv = new RequiredFieldValidator
			{
				Display = ValidatorDisplay.Dynamic,
				Text = ControlPanel.RequiredField_DefaultText,
				ErrorMessage = string.Format(ControlPanel.RequiredField_DefaultErrorMessage, question.Title),
				ControlToValidate = _tb.ID,
				ValidationGroup = "Form"
			};
			Controls.Add(_rfv);
		}
开发者ID:meixger,项目名称:n2cms,代码行数:33,代码来源:TextControl.cs

示例11: CreateChildControls

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            Label lblQuestion = new Label();
            _dpAnswer = new DatePickerControl();
            _dpAnswer.SkinID = "Survey";
            _dpAnswer.Text = _answer;
            RequiredFieldValidator valQuestion = new RequiredFieldValidator();

            lblQuestion.ID = "lbl" + _question.QuestionGuid.ToString().Replace("-", String.Empty); ;
            _dpAnswer.ID = "dp" + _question.QuestionGuid.ToString().Replace("-", String.Empty);
            valQuestion.ID = "val" + _question.QuestionGuid.ToString().Replace("-", String.Empty);

            lblQuestion.Text = _question.QuestionText;
            lblQuestion.AssociatedControlID = _dpAnswer.ID;

            valQuestion.ControlToValidate = _dpAnswer.ID;
            valQuestion.Enabled = _question.AnswerIsRequired;

            valQuestion.Text = _question.ValidationMessage;

            Controls.Add(lblQuestion);
            Controls.Add(_dpAnswer);
            Controls.Add(valQuestion);
        }
开发者ID:saiesh86,项目名称:TravelBlog,代码行数:25,代码来源:DateQuestion.cs

示例12: GetRequiredFieldValidator

 protected RequiredFieldValidator GetRequiredFieldValidator(Control control)
 {
     var requiredFieldValidator = new RequiredFieldValidator();
     requiredFieldValidator.ControlToValidate = control.ID;
     requiredFieldValidator.SetFocusOnError = true;
     requiredFieldValidator.ErrorMessage = MandatoryErrorMessage;
     return requiredFieldValidator;
 }
开发者ID:jeppe-andreasen,项目名称:Umbraco-Public,代码行数:8,代码来源:FormsField.cs

示例13: ExibirCritica

        public void ExibirCritica(string critica)
        {
            RequiredFieldValidator validator = new RequiredFieldValidator();
            validator.ErrorMessage = critica;
            validator.IsValid = false;

            Page.Validators.Add(validator);
        }
开发者ID:ViniciusConsultor,项目名称:sistema-gestao-social,代码行数:8,代码来源:Login.aspx.cs

示例14: AddValidator

 private void AddValidator()
 {
     RequiredFieldValidator rfv = new RequiredFieldValidator();
     rfv.ID = "RequiredFieldValidator2";
     rfv.ControlToValidate   = this.TextBox2.ID;
     rfv.ErrorMessage = "Value is required for this field";
     Page.Controls.Add(rfv);
 }
开发者ID:iali,项目名称:gittest,代码行数:8,代码来源:Default.aspx.cs

示例15: CreateChildControls

        protected override void CreateChildControls()
        {
            input = new TextBox();
            input.ID="input";
            this.Controls.Add(input);
            validator=new RequiredFieldValidator();
            validator.ID="Valinput";
            validator.ControlToValidate=input.ID;

        }
开发者ID:ananth039,项目名称:Anantha-Kumar-.net-Practice-programs,代码行数:10,代码来源:RequiredTextbox.cs


注:本文中的System.Web.UI.WebControls.RequiredFieldValidator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。