检查c#中的空数据

问题描述 投票:1回答:1

我正在使用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

enter image description here

c# webforms alert ajaxcontroltoolkit hidden-field
1个回答
0
投票

喜欢这个:

© www.soinside.com 2019 - 2024. All rights reserved.