如果在后面的代码中进行验证 [英] If else validation in code behind
本文介绍了如果在后面的代码中进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用if-else语句验证代码后的页面.我不需要asp.net验证程序.
如果不是这样,则说明工作正常.但是问题是页面在执行其他条件时仍在提交.
我想要当我单击保存"按钮并且执行达到其他条件时,页面设置为无效.或者当代码在else语句中时我需要阻止页面
Hi,
I am validating page in code behind using if-else statement. i didn''t need asp.net validator for this.
If else statement working fine. but the problem is that page is still submitting when it execute else condition.
I want when i click save button and when execution reach in else condition , the page set to invalid. or it i need to prevent page when code is in else statement
EntityMpdb1 obentitympdb1 = new EntityMpdb1();
BalLoginTable obupdatepensioner = new BalLoginTable();
DataSet dspensionrecord = new DataSet();
BalLoginTable obbalpensionrecord = new BalLoginTable();
try
{
obentitympdb1.Authority_No = Txtauthorityno.Text;
Match match = Regex.Match(Txtauthoritydate.Text, @"^([1-9]|0[1-9]|1[0-2])[- / .]([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])[- / .](1[9][0-9][0-9]|2[0][0-9][0-9]|3[0][0-9][0-9])$");
if (match.Success)
{
string val = match.Groups[1].Value;
}
else
{
spstartdate.InnerText = "Please enter correct date";
}
obupdatepensioner.updatepensionderdetail(obentitympdb1);
}
catch
{
}
推荐答案
"); 如果(匹配成功) { 字符串 val = match.Groups [ 1 ].Value; } 其他 { spstartdate.InnerText = " ; } obupdatepensioner.updatepensionderdetail(obentitympdb1); } 捕获 { }
"); if (match.Success) { string val = match.Groups[1].Value; } else { spstartdate.InnerText = "Please enter correct date"; } obupdatepensioner.updatepensionderdetail(obentitympdb1); } catch { }
在其他部分使用此代码:
Use this code in else part:
ClientScript.RegisterStartupScript("msg", "alert('Enter valid UserName and Password.');", true);
txtUserName.Text = "";
txtPassword.Text = "";
txtUserName.Focus();
您也可以尝试以下方法....
从 else 抛出异常,并使用异常处理来处理它....
问候
Sebatian
You can try the following too....
Throw an exception from else, and handle it using exception handling....
Regards
Sebatian
这篇关于如果在后面的代码中进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文