The Error in your code is that
Button btn = Page.FindControl("btndefer") as Button;
btn.Attributes.Add("onClick","javascript:window.open('DeferReason.aspx','width=500,height=245,left=350,top=400')");
when you write this code what .net does is this in html
<input type="submit" önclick="javascript:window.open(" deferreason.aspx="," width="500,height=245,left=350,top=400')'" value="Error Code"></input>
So in the above you see that the before the onClick .net puts single Quotes and you have put single Quotes in the code as well so it the quotes is the problem
So try this
Button btn = Page.FindControl("btndefer") as Button;
btn.Attributes.Add("onClick","javascript:window.open(\'DeferReason.aspx\',\'_blank\',\'width=500,height=245,left=350,top=400\')");
See this revised code