提交表单后出现链接按钮问题

时间:2015-06-05 11:56:27

标签: c# asp.net

大家好我有以下代码回到上一个表格

<asp:LinkButton ID="hlBack" runat="server" OnClientClick="history.back(); return false;" CausesValidation="false">Go Back</asp:LinkButton>
        &nbsp;<asp:LinkButton ID="lbSubmit" runat="server" OnClick="btnSubmit_Click">Submit</asp:LinkButton>

如果我没有提交表单,哪个有效,但在btnSubmit_Click我正在执行以下代码验证

 protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string sEmails = txtareaEMail.Value;
        bool bValid = ValidateEmailAddress(sEmails);
        if (bValid)
        { }
    }

private bool ValidateEmailAddress(string sEmails)
    {
        //remove single quote from email address
        sEmails = sEmails.Replace("'", "");

        char[] delimiter = new char[] { ';' };
        string[] arPart = sEmails.Split(delimiter);

        // Create a new Regex object.
        Regex rx = new Regex(@"[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,3}");

        //only allow one email address per request
        if (arPart.Length < 1)
        {

            lblEmailMessage.Visible = true;

            lblEmailMessage.Text = "Please enter associate's email address.";

            return false;
        }
        else
        {
            for (int i = 0; i < arPart.Length; i++)
            {

                string sEmailAddress = arPart[i];

                sEmailAddress = sEmailAddress.Trim();

                if (!rx.IsMatch(sEmailAddress))
                {
                    lblEmailMessage.Visible = true;

                    lblEmailMessage.Text = sEmailAddress + " is invalid. " + "Please enter a valid email address.";

                    return false;
                }
            }
            return true;
        }
    }

当我验证它并返回false时,返回不起作用,所以有人可以帮助我

1 个答案:

答案 0 :(得分:1)

替换你的LinkBut​​ton
<a  href="#" onclick="history.go(-1);">Go Back</a>