本文介绍了requiredfieldvalidator在updatepanel内部无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在网格视图外部的外部按钮创建网格视图中的新行,动态创建下拉列表并验证它。它曾经工作正常,直到我在更新面板中移动网格视图。 有没有办法验证UpdatePanel中的下拉列表? 这是我到目前为止的代码: DropDownList ddlEmployeeName1 = new DropDownList(); ddlEmployeeName1.ID = ddlEmployeeName1; ddlEmployeeName1.Attributes.Add( runat, server); ddlEmployeeName1.Width = 200 ; ddlEmployeeName1.ValidationGroup = valSave; ddlEmployeeName1.CausesValidation = true ; DropDownList ddlEmployeeRole = new DropDownList(); ddlEmployeeRole.ID = ddlEmployeeRole; ddlEmployeeRole.Attributes.Add( runat, server); if (!generic.isRowDataSaved) { // e.Row.Cells [1] .Controls.Add(lblEmployeeCode); e.Row.Cells [ 2 ] Controls.Add被(ddlEmployeeName1)。 e.Row.Cells [ 3 ]。Controls.Add(ddlEmployeeRole); // 文本框被添加为网格的最后一列 列表< employeebo> employeeList = new 列表< employeebo>(); EmployeeService employeeService = new EmployeeService( this .ContextBO); lblPoNumberIns1.Text = PO12345; ddlEmployeeName1.EnableViewState = true ; ddlEmployeeName1.AppendDataBoundItems = true ; ddlEmployeeName1.AutoPostBack = true ; employeeList = employeeService.GetEmployeeList(); // (List< employeebo>)Session [UIConstants.GetEmployeeList] ; ddlEmployeeName1.DataSource = employeeList; ddlEmployeeName1.Items.Add( new ListItem( 请选择EmployeeName, 0)); ddlEmployeeName1.Font.Size = FontUnit.XXSmall; ddlEmployeeName1.Width = 200 ; ddlEmployeeName1.CausesValidation = true ; ddlEmployeeName1.DataTextField = EmployeeName; ddlEmployeeName1.DataValueField = EmployeeOrbitCode; ddlEmployeeName1.DataBind(); ddlEmployeeName1.Attributes.Add( onChange, 返回empOrbitCodeUpd(this, + e.Row.RowIndex + );); RequiredFieldValidator nameValidator = new RequiredFieldValidator(); if (ddlEmployeeName1.SelectedValue.ToString()== 0) { nameValidator.ControlToValidate = ddlEmployeeName1.UniqueID; nameValidator.Attributes.Add( runat, server); nameValidator.ErrorMessage = 请选择EmployeeName; nameValidator.Font.Size = FontUnit.XXSmall; nameValidator.ID = nameValidator; nameValidator.Display = ValidatorDisplay.Dynamic; nameValidator.SetFocusOnError = true ; nameValidator.ValidationGroup = valSave; nameValidator.InitialValue = 0; nameValidator.Text = *; this .Form.Controls.Add(nameValidator); } 解决方案 使用< scriptmanager> < updatepanel>之外的标记标签 I am creating the new row inside the grid view from external button present outside the grid view with dynamically creating the dropdownlist and validating it. It used to work fine until I have moved the grid view inside the update panel.Is there any way to validate the dropdownlist inside the UpdatePanel?Here's my code so far:DropDownList ddlEmployeeName1 = new DropDownList();ddlEmployeeName1.ID = "ddlEmployeeName1";ddlEmployeeName1.Attributes.Add("runat", "server");ddlEmployeeName1.Width = 200;ddlEmployeeName1.ValidationGroup = "valSave";ddlEmployeeName1.CausesValidation = true;DropDownList ddlEmployeeRole = new DropDownList();ddlEmployeeRole.ID = "ddlEmployeeRole";ddlEmployeeRole.Attributes.Add("runat", "server");if (!generic.isRowDataSaved){ // e.Row.Cells[1].Controls.Add(lblEmployeeCode); e.Row.Cells[2].Controls.Add(ddlEmployeeName1); e.Row.Cells[3].Controls.Add(ddlEmployeeRole); //textbox is added as last column of grid List<employeebo> employeeList = new List<employeebo>(); EmployeeService employeeService = new EmployeeService(this.ContextBO); lblPoNumberIns1.Text = "PO12345"; ddlEmployeeName1.EnableViewState = true; ddlEmployeeName1.AppendDataBoundItems = true; ddlEmployeeName1.AutoPostBack = true; employeeList = employeeService.GetEmployeeList();//(List<employeebo>)Session[UIConstants.GetEmployeeList]; ddlEmployeeName1.DataSource = employeeList; ddlEmployeeName1.Items.Add(new ListItem("Please Select EmployeeName", "0")); ddlEmployeeName1.Font.Size = FontUnit.XXSmall; ddlEmployeeName1.Width = 200; ddlEmployeeName1.CausesValidation = true; ddlEmployeeName1.DataTextField = "EmployeeName"; ddlEmployeeName1.DataValueField = "EmployeeOrbitCode"; ddlEmployeeName1.DataBind(); ddlEmployeeName1.Attributes.Add("onChange", "return empOrbitCodeUpd(this," + e.Row.RowIndex + ");"); RequiredFieldValidator nameValidator = new RequiredFieldValidator(); if (ddlEmployeeName1.SelectedValue.ToString() == "0") { nameValidator.ControlToValidate = ddlEmployeeName1.UniqueID; nameValidator.Attributes.Add("runat", "server"); nameValidator.ErrorMessage = "Please Select EmployeeName"; nameValidator.Font.Size = FontUnit.XXSmall; nameValidator.ID = "nameValidator"; nameValidator.Display = ValidatorDisplay.Dynamic; nameValidator.SetFocusOnError = true; nameValidator.ValidationGroup = "valSave"; nameValidator.InitialValue = "0"; nameValidator.Text = "*"; this.Form.Controls.Add(nameValidator); } 解决方案 use the <scriptmanager> tag outside the <updatepanel> tag 这篇关于requiredfieldvalidator在updatepanel内部无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 19:11