ASP.NET - Open new window from gridview RowCommand

Asked By Annie X on 14-Sep-10 05:42 AM
Hi, hope you can.

I'm trying to get a new window to open when i click a link in a gridview. Until now i have been using this

Response.Redirect("BulletinMsg.aspx?varBulletinID=" & e.CommandArgument, False)

but this will not open a new window.

I've tried the code below but i keep getting the following error msg

Line: 938
Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '<script>window.open('.

Protected Sub gvListBulletins_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvListBulletins.RowCommand

If e.CommandName = "lnkBtnTitle" Then

Response.Write("<script>")

Response.Write("window.open('BulletinAdd.aspx?varBulletinID='" & e.CommandArgument & ",'_blank')")

Response.Write("</script>")

End If

End Sub

Any ideas how i get this to work.

Many thanks AnnieX

.net starter replied to Annie X on 14-Sep-10 05:48 AM

hi,
  try to add the attributes for linkbutton on RowDataBound of gridview.
  for eg.
in RowDataBound event of gridview

if (e.Row.RowType == DataControlRowType.DataRow)
{
((LinkButton)(e.Row.FindControl("lbuttonName"))).Attributes.Add("onclick","JSwinopenfunction");
}
sri sri replied to Annie X on 14-Sep-10 06:00 AM
hi,

try the below code


<asp:gridview id="grd" runat="server"....>
<Columns>
<asp:TemplateField>
<ItemTemplate>

<a href = 'javascript:NewWindow(<%# Eval("EmployeeID")%>)'>Click Here </a>
</ItemTemplate>
</asp:templateField>

---
---
---

</columns>
</asp:gridview>

<script language="javascript">
function NewWindow(para)
{
   window.open('NewPage.aspx?eID=' + para)
}
</script>
Annie X replied to sri sri on 14-Sep-10 06:07 AM
Hi. Thanks you for the help that has done the trick.

All the best
AnnieX
sri sri replied to Annie X on 14-Sep-10 06:32 AM
:-)