textboxes reads empty string (“”) when i press submit button!
-
05-07-2019 - |
Question
I have a form , with 5 textboxes, 1 radiobutton group (4 radiobuttons) , and a submit button, i added some "code behind" to handle cases where a user doesnt fill in all the fields,
something like
if (question.Value == "") // question = a textbox with runat=server property
{
// handle error
}
the problem is that, the 1st time i fill the form,and click submit, it always sends empty values :S in other words. the above snippet of code will always be true :S can some1 explain to me where did i go wrong ?
note: if the same question been asked before.. please link me..
Solution
You might want to check and see if you databinding on your button post back is not blanking out your textboxes. You can use;
if(!Page.IsPostBack) { // more code here }
to make sure that your input items keep their values when you click your button.
OTHER TIPS
Assuming question is a textbox, you want question.Text