buttoncolumn and target=_blank

collie

New member
buttoncolumn and target=_blank

Hi, I have a dg with a button column. When the user clicks the button I want a new page to open. I am using DataGrid1_ItemCommand as I have a few buttons and I need to pass several parameters in my url such as: <code> Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand If e.Item.ItemIndex >= 0 Then Dim userCell As TableCell = e.Item.Cells(0) Dim ad_id As String = userCell.Text Dim posterCell As TableCell = e.Item.Cells(1) Dim ad_poster As String = posterCell.Text Dim cat_cell As TableCell = e.Item.Cells(12) Dim cat_id As String = cat_cell.Text Dim sub_cell As TableCell = e.Item.Cells(13) Dim sub_id As String = sub_cell.Text If e.CommandSource.commandname = "siteAd" Then Response.Redirect("http://www.mysite.com/ads.aspx?cat_id=" & cat_id & "&sub_id=" & sub_id & "&ad_id=" & ad_id) End If </code> The problem is that I am not sure how to open the link in a new page. Can someone please help? Thanks​
 

yuval k

New member
You can't redirect to another

window - that's the difference between client side and server side. On the other hand, you can write a JavaScript script to the client, which will be responsible for opening the page in another window.​
 

collie

New member
code

Hi, Thanks for the response. Below is my code. When I don't pass parameters then it works fine however when I pass the parameters it says that cat_id isn't defined. How can I solve it? Thanks. If e.Item.ItemIndex >= 0 Then Dim userCell As TableCell = e.Item.Cells(0) Dim ad_id As String = userCell.Text Dim posterCell As TableCell = e.Item.Cells(1) Dim ad_poster As String = posterCell.Text Dim cat_cell As TableCell = e.Item.Cells(12) Dim cat_id As String = cat_cell.Text Dim sub_cell As TableCell = e.Item.Cells(13) Dim sub_id As String = sub_cell.Text If e.CommandSource.commandname = "siteAd" Then Dim scriptString As String = "<script language=JavaScript>" & "window.open('http://www.ybay.co.il/ads.aspx?cat_id=' & cat_id & ' & sub_id = ' & sub_id & ' & ad_id = ' & ad_id )" scriptString += "<" scriptString += "/" scriptString += "script>" If (Not Me.IsStartupScriptRegistered("Startup")) Then Me.RegisterStartupScript("Startup", scriptString) End If end if​
 
למעלה