1

I am writing a project using ASP.NET C#.

I want to implement linkbutton click event to open new page in a new tab, but before I have to create new session variable. I have tried this:

protected void LinkButton_Click3(Object sender, EventArgs e)
        {
            string p_id = (sender as LinkButton).CommandArgument;
            Session["p_id"] = p_id;
            Response.Write("<script type='text/javascript'> window.open('details.aspx','_blank'); </script>");

        }

But it doesn't work anyway.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Nurlan
  • 2,860
  • 19
  • 47
  • 64
  • Make sure your popup blocker isnt suppressing the window. – StingyJack Aug 09 '12 at 17:37
  • Does the postback happen? Do you see the script in the generated HTML? – Vlad Aug 09 '12 at 17:40
  • yes it happens. If I write Response.Redirect("details.aspx"); instead response.write(..); I redirect to details.aspx but in the same window – Nurlan Aug 09 '12 at 17:46
  • This should not be flagged as a duplicate. Just because a few people think you should use response.redirect does not mean it is the same question. This happens all too often from people thinking they know everything. Response.Redirect absolutely will not work with my project. – Brad Jun 21 '16 at 17:19

3 Answers3

1

Based on your comments, you should disable your popup blocker.

StingyJack
  • 19,041
  • 10
  • 63
  • 122
0

Try this, call this function on button click or document.ready only on page where you want to redirect from.

<script type="text/javascript">
function newTab() 
{
  if (opener.document.getElementById("aspnetForm").target != "_blank") return;   

opener.document.getElementById("aspnetForm").target = "";
opener.document.getElementById("aspnetForm").action = opener.location.href;

}

</script

or add this to linkbutton html

OnClientClick="aspnetForm.target ='_blank';"
rs.
  • 26,707
  • 12
  • 68
  • 90
0

Sometimes it works for me to just declare whatever I would invoke dynamically from the administrated code into a javascript function and just call it from within with the RegisterClientScriptBlock method in ClientScript class:

Daclare the window.open function:

    <script type="text/javascript">
        function SetRedirect(URI) {
           window.open(URI, "Details", "menubar=no, location=no, resizable=yes, scrollbars=yes, status=yes, width = 1200, height = 600");
        }
    </script>

And from within the code behind class just a gateway caller to this function like:

void MessageGateway(string URI)
{
    this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
        "logCallBack", @"<script type=""text/javascript"">SetRedirect('" + URI + "');</script>");
}

And that's it, you may call this gateway with your stuff as normally you do,

MessageGateway(string.Format("../IRMQueryPO.aspx?id={0}", e.Item.Cells[2].Text));

You can try tweeking the "target" parameter with "_blank" in order to open a tab instead a window, it's just a matter of the flavor your solution points in.