At the first code review the error seems to be generated in your
btn_Submit_Click
method from the next line:
if (ViewState["ans"].ToString() == txtans.Text)
The value from
ViewState
may be
null
, so you should correct it with:
if (ViewState["ans"] != null && ViewState["ans"].ToString() == txtans.Text)
PS: You forgot to mention the line of code that generate the error.