Opening new window from button/link button on ASP.net 2.0/3.5

I Googled for the solution and never found one that is simple, short and to the point. Here is the fastest solution to opening a link in a new page if you are using a button or a link button on ASP.NET 2.0/3.5. Add this attribute to your button. This goes on your page load section of the code.
button1.Attributes.Add("onclick", "window.open('somepage.aspx');")
Unfortunately I could not find a solution using response.redirect
FacebookTwitterGoogle+Share

Converting a grid to excel document in vb.net

A little script to convert a gridview to an excel document. This always came handy when someone needed to create a report right out of gridview ... You can call the function like this ...
ExportGridToExcel(grd, "report.xls")
 
---Copy the code below and paste it in your script
 
Public Sub ExportGridToExcel(ByRef grdGridView As GridView, ByVal fileName As String)
 
Response.Clear()
 
Response.AddHeader("content-disposition", String.Format("attachment;filename={0}.xls", fileName))
 
Response.Charset = ""
 
Response.ContentType = "application/vnd.xls"
 
Dim strWriter As New StringWriter()
 
Dim HtmlWriter As New HtmlTextWriter(strWriter)
 
grdGridView.RenderControl(HtmlWriter)
 
Response.Write(strWriter.ToString)
 
Response.End()
 
End Sub
 
Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
 
'You will need this part else you will get error like "runat=server needs to be before ....."
 
End Sub