Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Program not working

There are text boxes which have to be disabled and enabled based on the incoming fields

Having problem with the following codes



if (string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE2"].Value.ToString()) ||
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE4"].Value.ToString()) ||
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE3"].Value.ToString()) ||
!string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE1"].Value.ToString())) ;
{
txt_Resp_time2.Text = SqlCmd.Parameters["@ERESPTIME2"].Value.ToString();
txt_Response2.Text = SqlCmd.Parameters["@ERESPONSE2"].Value.ToString();
txt_Resp_time2.Enabled= true;
txt_Response2.Enabled = true;
txt_Response2.Focus();

txt_Resp_time4.Enabled = false;
txt_Response4.Enabled = false;
txt_Resp_time3.Enabled = false;
txt_Response3.Enabled = false;
txt_Resp_time1.Enabled = false;
txt_Response1.Enabled = false;
}


if (string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE1"].Value.ToString()) ||
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE4"].Value.ToString()) ||
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE3"].Value.ToString()) ||
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE2"].Value.ToString())) ;
{
txt_Resp_time1.Text = SqlCmd.Parameters["@ERESPTIME1"].Value.ToString();
txt_Response1.Text = SqlCmd.Parameters["@ERESPONSE1"].Value.ToString();
txt_Resp_time1.Enabled= true;
txt_Response1.Enabled = true;
txt_Response1.Focus();

txt_Resp_time4.Enabled = false;
txt_Response4.Enabled = false;
txt_Resp_time3.Enabled = false;
txt_Response3.Enabled = false;
txt_Resp_time2.Enabled = false;
txt_Response2.Enabled = false;
}

What I have tried:

This are codes which I have tried and not been able to solve
Posted
Updated 9-Oct-17 14:07pm
Comments
Richard MacCutchan 9-Oct-17 13:21pm    
Solve what?

1 solution

Please describe a few more details about your question:
Is this your actual code copy-pasted from your program?
What are the value of your ERESPONSE1-4 parameters?
What behavior do you see?
What behavior do you expect?
Is only the focus a problem or also the enabled/disabled controls?

Without this information it is difficult to propose a solution as we are not mind readers.

However, if this is your program, I see a problem:
if (string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE1"].Value.ToString()) ||
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE4"].Value.ToString()) || 
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE3"].Value.ToString()) ||
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE2"].Value.ToString())) ; 
{

The if contains 4 lines of conditions that are followed by a semicolon ";"
This completes your if with an empty body and the following block is executed regardless of the evaluation of the if conditions.
This is equivalent to this:
if (string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE1"].Value.ToString()) ||
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE4"].Value.ToString()) || 
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE3"].Value.ToString()) ||
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE2"].Value.ToString()))
{
}

{

So if your behavior is always the 1 fields are enabled and all others are disabled, try removing the ";" immediately after the if and see, if this solves your problem.
if (string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE1"].Value.ToString()) ||
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE4"].Value.ToString()) || 
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE3"].Value.ToString()) ||
string.IsNullOrEmpty(SqlCmd.Parameters["@ERESPONSE2"].Value.ToString()))
{
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900