【发布时间】:2018-06-01 19:54:10
【问题描述】:
我想在动态 asp:table 中的控件(以文本框为例)上添加一些必需的验证器。
代码:
foreach (KeyValuePair<string, string> o in Collection)
{
TableRow Row = new TableRow();
TableCell valueCell = new TableCell();
TableCell Cell = new TableCell();
TextBox txtBox = new TextBox();
TextBox txtBox1 = new TextBox();
txtBox1.ID = o.Key + o.Value;
if (o.Value.Contains("Mandatory"))
{
RequiredFieldValidator req = new RequiredFieldValidator();
req.ErrorMessage = "Required";
req.BorderColor = System.Drawing.Color.Red;
req.ControlToValidate = txtBox1.ID;
req.Enabled = true;
req.Display = ValidatorDisplay.Dynamic;
Cell.Controls.Add(req);
}
valueCell.Controls.Add(txtBox1);
Row.Cells.Add(valueCell);
Row.Cells.Add(Cell);
table.Rows.Add(Row);
}
但我收到此错误:
“System.web.dll 中的 System.Web.UnhandledException”
上线Row.Cells.Add(Cell);
你能帮帮我吗?
【问题讨论】:
-
请提供异常的详细信息 - 至少是消息。
-
如何获得有关此异常的一些详细信息?因为 VS 没有打开标准的异常窗口。
-
作为一种快速解决方案,您可以将代码包装在
try / catch块中,并在catch块中放置断点。 -
哪一行抛出异常?
-
System.Web.HttpUnhandledException 发生消息:抛出异常:System.Web.dll 中的“System.Web.HttpUnhandledException” 表达式计算器中的内部错误。此行导致错误:Row.Cells.Add(Cell);
标签: c# asp.net dynamic controls requiredfieldvalidator