我正在为文本框创建一个自定义控件。当文本框的操作为 编辑 时,它将呈现与文本框相同的样式。另一方面,当文本框的操作为 查看 时,它将呈现为标签。但现在我遇到了一个问题,当文本框的操作为编辑时,如何使用必填字段验证器验证我的文本框?以下是我的代码:
[ToolboxData(@"<{0}:cusTextBox runat=""server"" Action=""Edit"" />")]
public class cusTextBox:TextBox
{
public string Action
{
get
{
String s = (String)ViewState["Action"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Action"] = value;
}
}
public override void RenderControl(HtmlTextWriter writer)
{
if (Action ==gbcCommandVariable.CommandEdit)
{
base.RenderControl(writer);
}
else if (Action == gbcCommandVariable.CommandView)
{
writer.Write(String.Format(@"<span ID=""{0}"" style=""display:inline-block; white-space:inherit"" >{1}</span> ", this.ClientID, this.Text));
}
}
}
我的前端
<cc1:cusTextBox ID="cusTextBox1" runat="server" Action="View" ></cc1:cusTextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click1"
Text="Button" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="cusTextBox1"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
Please help me .Urgent.THanks