You are using URL with ~ and it won’t recognize by javascript. You should process url with ~ by using ResolveUrl method which
converts a URL into one that is usable on the requesting client(c)msdn
In your case:
Response.Write(String.Format("window.open('{0}','_blank')", ResolveUrl(pageurl)));