Assume,
if Request.QueryString["res"] it is Null, What happens in second line.
Your are trying to
Conversion of null to string.
That is reason for getting
'Object reference not set to an instance of an object'
error.
So, What you have to do is,
Check if Query string is not null then do conversion. like this
if(Request.QueryString["res"]!=null)
{
XResult = Request.QueryString["res"];
TextBox1.Text = XResult.ToString();
}
else
{
}