我正在使用c#,并且我有一个Hidden Field
<asp:HiddenField runat="server" ID="hidJsonHolder" ClientIDMode="Static" />
如何添加警报,以便可以检查object obj
是否从Hidden Field
获取空数据?
我尝试使用RegularExpressionValidator
,但回复错误
<asp:HiddenField runat="server" ID="hidJsonHolder" ClientIDMode="Static" />
<asp:RegularExpressionValidator Display="Dynamic"
ControlToValidate="hidJsonHolder"
ID="RegularExpressionValidator1"
runat="server" ErrorMessage="error"
ValidationGroup="Validation2"></asp:RegularExpressionValidator>
此其他代码不警报
protected void btnFinal_Click(object sender, EventArgs e)
{
JavaScriptSerializer jsSer = new JavaScriptSerializer();
object obj = jsSer.DeserializeObject(hidJsonHolder.Value);
if (obj != null)
{
Movie[] listMovie = jsSer.ConvertToType<Movie[]>(obj);
foreach (Movie p in listMovie)
{
string pattern = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
Regex re = new Regex(pattern);
if (p.ToString() != null)
{
MatchCollection matches = re.Matches(p.ToString());
if (matches.Count > 0)
{
for (int i = 0; i < matches.Count; i++)
{
Response.Write(matches[i] + "; ");
}
}
}
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Msg", "alert('Error.');", true);
}
}
编辑#1
喜欢这个: