According to your description, I see that you were using the Response.Write when the updatepanel async post back.
As we all know that we can't use Response.Write during an asynchronous postback. If you want to use it when gridview paging or sorting.
I think you should set it as PostBackTrigger of updatepanel. Like below
<triggers>
<asp:postbacktrigger controlid="GridView1" xmlns:asp="#unknown" />
</triggers>