It seems to be obvious - your output parameter (@val) get NULL as value!
If this is an unacceptable result you must check your SP.
If this is an acceptable result change this line:
TxtValue.Text = Cmd.Parameters("@val").Value
to this:
TxtValue.Text = Convert.ToString(Cmd.Parameters("@val").Value)