我的C#代碼如下所示。多個條件檢查單按鈕點擊
if(TextBox1.Text.Length > 5)
{
if(TextBox2.Text.Length > 5)
{
if(TextBox3.Text.Length > 5)
{
if(TextBox4.Text.Length > 5)
{
//Action to pass to the next stage.
}
else
{
error4.text = "Textbox4 value should be minimum of 5 characters.";
}
}
else
{
error3.text = "Textbox3 value should be minimum of 5 characters.";
}
}
else
{
error2.text = "Textbox2 value should be minimum of 5 characters.";
}
}
else
{
error1.text = "Textbox1 value should be minimum of 5 characters.";
}
1)在上述樣品中。我正在使用嵌套的If-Else概念,在按鈕單擊時,如果TextBox1值小於5,則將移動到else部分並顯示error1值,但不會檢查是否存在其他錯誤。
2)如果我改變如果條件一步一步如果條件那麼它不會對我有用,因爲只有在所有的IF條件都滿足的情況下,動作才能完成。
3)如果我使用& &運營商要檢查所有的條件我不會得到個別錯誤給每個「錯誤標籤」
如何,我可以檢查多個IF上的一個按鈕點擊的條件?
我的原代碼
if (checkavail == "available")
{
if (name.Text.Length > 0)
{
if (email.Text.Length > 5)
{
if (password1.Text.Length > 7 && password1.Text == password2.Text)
{
if (alternate.Text.Contains("@") && alternate.Text.Contains("."))
{
if (question.Text.Length > 0)
{
if (answer.Text.Length > 0)
{
Response.Redirect("next_page.aspx");
}
else
{
error5.Text = "Please enter your security answer";
}
}
else
{
error4.Text = "Please enter your security question";
}
}
else
{
error3.Text = "Invaild alternate email address";
}
}
else
{
error2.Text = "Password should be minimum 8 characters and must match confirm password";
}
}
else
{
error1.Text = "Email address should be minimum 6 characters";
}
}
else
{
error.Text = "Please enter your name";
}
}
else
{
error1.Text = "This email address is already taken. Please try another";
}
我需要重定向時的操作,滿足所有條件來完成。如果發現多個錯誤,則每個錯誤都應得到每條錯誤消息。
向我們展示整個功能 – 2011-12-24 04:52:55
@JoePhilllips - 已添加代碼。 – 2011-12-24 04:56:43