Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在asp.net表单中应用RequiredValidator后接收空字段_C#_Asp.net_Forms_Validation_Requiredfieldvalidator - Fatal编程技术网

C# 在asp.net表单中应用RequiredValidator后接收空字段

C# 在asp.net表单中应用RequiredValidator后接收空字段,c#,asp.net,forms,validation,requiredfieldvalidator,C#,Asp.net,Forms,Validation,Requiredfieldvalidator,我面临的问题是,在我的表格中,我已经给出了requiredfield验证,根据我的测试,它运行良好,但仍然收到带有空字段的背靠背电子邮件。我有一个文本框,用户必须在其中填写他们的联系号码并提交到我的邮件ID中的表格。我已经测试了100次,每次如果数字字段为空,它都不接受表格提交,但不知道我为什么会收到带有空值的邮件。是否存在任何可以克服验证的漏洞?下面是我正在使用的代码 <asp:TextBox ID="callBackNumber2" runat="server" CssClass="f

我面临的问题是,在我的表格中,我已经给出了requiredfield验证,根据我的测试,它运行良好,但仍然收到带有空字段的背靠背电子邮件。我有一个文本框,用户必须在其中填写他们的联系号码并提交到我的邮件ID中的表格。我已经测试了100次,每次如果数字字段为空,它都不接受表格提交,但不知道我为什么会收到带有空值的邮件。是否存在任何可以克服验证的漏洞?下面是我正在使用的代码

<asp:TextBox ID="callBackNumber2" runat="server" CssClass="field-pitch" MaxLength="10"></asp:TextBox>
<asp:RequiredFieldValidator ID="r1" runat="server"
ControlToValidate="callBackNumber2" CssClass="validator" 
ErrorMessage="Please enter call back number" style="position:relative; 
top:-20px" ValidationGroup="callBack2"></asp:RequiredFieldValidator>

            <span class="field-title">Nature Of Request</span>
            <asp:DropDownList ID="callBackNature" runat="server" CssClass="field-pitch">
                <asp:ListItem>Information about product</asp:ListItem>
                <asp:ListItem>Need a Price Quote</asp:ListItem>
                <asp:ListItem>Existing Order</asp:ListItem>
            </asp:DropDownList>

            <asp:Button ID="makeCallBack2" runat="server" Text="Submit" CssClass="gen-button" ValidationGroup="callBack2" />

请求的性质
产品信息
需要报价吗
现有订单
按钮点击事件

if (Page.IsValid) {
    try {
        MailMessage mail = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient();
        mail.To.Add("main@abc.com");
        mail.CC.Add("sample@abc.com");
        mail.From = new MailAddress(mailTo.Text);
        mail.Subject = "Call Back Request From " + callBackNumber2.Text + "";
        mail.Body = "Call back Number - " + callBackNumber2.Text + "<br />Nature Of Request - " + callBackNature.SelectedItem.ToString + "<br />Source - " + Request.Url.AbsoluteUri + "<br />IP - " + ipaddress + "";
        mail.IsBodyHtml = true;
        SmtpServer.Port = 25;
        SmtpServer.Credentials = new System.Net.NetworkCredential(mailTo.Text, mailPassword.Text);
        SmtpServer.Host = "relay-hosting.secureserver.net";
        SmtpServer.EnableSsl = false;
        SmtpServer.Send(mail);
        mpCallBack.Show();
        callBackResponse.Visible = true;
        callBackContent.Visible = false;
    } catch (Exception ex) {
        Response.Write(ex);
    }
}
if(Page.IsValid){
试一试{
MailMessage mail=新的MailMessage();
SmtpClient SmtpServer=新的SmtpClient();
mail.To.Add(“main@abc.com");
mail.CC.Add(“sample@abc.com");
mail.From=新邮件地址(mailTo.Text);
mail.Subject=“来自“+callBackNumber2.Text+”的回拨请求;
mail.Body=“回拨号码-”+callBackNumber2.Text+”
请求性质-“+callBackNature.SelectedItem.ToString+”
源-“+Request.Url.AbsoluteUri+”
IP-“+ipaddress+”; mail.IsBodyHtml=true; SmtpServer.Port=25; SmtpServer.Credentials=新系统.Net.NetworkCredential(mailTo.Text、mailPassword.Text); SmtpServer.Host=“relay hosting.secureserver.net”; SmtpServer.EnableSsl=false; 发送(邮件); mpCallBack.Show(); callBackResponse.Visible=true; callBackContent.Visible=false; }捕获(例外情况除外){ 答复.编写(ex); } }
为什么不在代码的开头使用if子句呢

if (callBackNumber2.Text != string.Empty)
{ your codes }

为什么不在代码的开头使用if子句呢

if (callBackNumber2.Text != string.Empty)
{ your codes }

我不是在寻找任何替代解决方案。我不是在寻找任何替代解决方案。