0

i have a page with drop down list and i have to open a new window with selected iteam's edit form

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    this.EntityGrid.Columns.Clear();
    EntityName.Text = DropDownList1.SelectedItem.Text;
    newEntity.Visible = true;
    newEntity.Text = DropDownList1.SelectedItem.Text;
    ...
}

the following works

protected void newEntity_Click(object sender, EventArgs e)
{
    var entity = newEntity.Text;
    Response.Redirect(entity + "Edit.aspx");
    ...
}

but how can i open in separate tab not new window.

user2167089
  • 151
  • 6
  • 20

3 Answers3

1

Open a separate window is a client feature, so you need to "inject" the javascript that tells the browser to do this.

Response.Write(
     string.Format(
        "<script>window.open('{0}','_blank');</script>", entity + "Edit.aspx"));

The parameter _blank tells the windows.open function to open a new window

Agustin Meriles
  • 4,866
  • 3
  • 29
  • 44
  • thank you Agustin popup is blocked how can i get it opened in new tab instead of new window – user2167089 May 14 '13 at 21:27
  • That's not a trivial problem... You can check the discussion on this post http://stackoverflow.com/questions/4907843/open-url-in-new-tab-using-javascript – Agustin Meriles May 14 '13 at 21:53
1

You need to direct the browser to open a new window - this cannot be done server side, so you have to do so in client side.

One option is, instead of Response.Redirect, use Response.Write to output JavaScript to open a new window (and redirect the current one).

Another option is to use a target="_blank" attribute on a link that will open a new window.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

You can forget about using JavaScript because the browser controls whether or not it opens in a new tab. Your best option is to do something like the following instead:

<form action="http://www.yoursite.com/dosomething" method="get" target="_blank">
    <input name="dynamicParam1" type="text"/>
    <input name="dynamicParam2" type="text" />
    <input type="submit" value="submit" />
</form>

This will always open in a new tab regardless of which browser a client uses due to the target attribute.

Tony
  • 364
  • 4
  • 3