asp.net - textbox is empty but still showing the count -
i have textbox1 field in asp.net , text area show count of records. want count records split , in textbox1 when textbox1 empty text area showing 1.
here code.
int contacts = textbox1.text.split(',').count(); textarea.text = contacts.tostring();
string.split returns @ least 1 string, if pass string.empty 1 string is input string(so in case string.empty).
.... if instance does not contain of characters in separator, returned array consists of single element contains instance.
you have check it, f.e. string.isnullorempty(or string.isnullorwhitespace):
int contacts = 0; if(!string.isnullorempty(textbox1.text)) contacts = textbox1.text.split(',').length;
Comments
Post a Comment