I have a dropdownlist (with values ‘CMC’ & ‘CHF’)and two textbox’s.
when i select an option from dropdownlist, a text box control appears (visibility is written in javascript).
when i enter a number into this textbox and hit the sumbit/next button it should save this information in database.
The logic works for the one option but its not working for the other!
Both the options have textbox’s assoicated with them, which are visible only when the respective option is selected.
the frontend logic works (i.e. the visibility) but when I enter a number for ‘txt_HFMN’ ( the option for this text box to appear
in the dropdown is ‘CHF’ and ‘CMC’ for textbox ‘txt_HFNumber’)
Here is the code in .cs file:
if (txt_HFNumber != null)
{
strHFNUM = txt_HFNumber.Text;
}
else if (txt_HFMN != null)
{
strHFNUM = txt_HFMN.Text;
}
else
{
strHFNUM = string.Empty;
}
I tried to debug it, to pin point the error. The above condition checks only for the ‘txt_HFNumber’, it never
checks the ‘else if’ part. even though I have entered a value in ‘txt_HFMN’ it checks for ‘txt_HFNumber’ and since
‘txt_HFNumber’ doesn’t exist in the front end/no value is entered in this textbox , it inserts a ‘null’ into the
database instead of ‘txt_HFMN’ entered value!
Advise.
Really appreciate your help.
I think you might want something a bit more like this, you’re checking to see if the textbox itself exists: