[英]I have a validation that stops the user navigating to the next window but when all fields are cleared goes to the next window
I am working on a project and I am trying to get my Navigation button to recognise when values already stored are cleared from the clear all fields button made.我正在做一个项目,我试图让我的导航按钮识别何时从清除所有字段按钮中清除已存储的值。 Its fine when I do not enter any values the first time but if I type them in and store them then clear all fields I press the navigation button then I progress onto the window without entering any details.
当我第一次不输入任何值时它很好,但如果我输入它们并存储它们然后清除所有字段我按下导航按钮然后我进入 window 而不输入任何细节。 Is there a way to solve this?
有没有办法解决这个问题?
here is my code: thank you.这是我的代码:谢谢。
private void clear_Click(object sender, RoutedEventArgs e)
{
//clears all fields to start again on enetring your details
if (SCNResult.Text == String.Empty || Nameresult.Text == String.Empty)
{
MessageBox.Show("You need to enter your details and store them before pressing this button");
return;
}
Nameresult.Text = " ";
box.Text = "";
namebox.Text = "";
SCNResult.Text = " ";
error.Text = " ";
//
}
/////END OF BUTTON////
private void comp_Click(object sender, RoutedEventArgs e)
{
// This instruction stops the user from continuing if they have not entered their details.
if (SCNResult.Text == String.Empty || Nameresult.Text == String.Empty)
{
MessageBox.Show("You need to enter your details before progressing to the next window");
return;
}
else
{
computing Nav1 = new computing();
Nav1.Show();
this.Close();
}
//end of instruction
//navigates to the next window
//
}
When you clear the fields:清除字段时:
Nameresult.Text = " "; //here is the problem
box.Text = "";
namebox.Text = "";
SCNResult.Text = " "; //here is the problem
error.Text = " ";
" "
is not an empty string, that's why your if
always return false
" "
不是一个空字符串,这就是为什么你的if
总是返回false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.