1

I have page "PictureLotFiles.aspx" that contains a CheckBoxList and a link(originally a hyperlink, but it doesn't work for me since it will not save the Session for me).

PicturesLotFiles.aspx
<asp:CheckBoxList ID="cblWarehouse" runat="server" Font-Size="10pt" Font-Names="Verdana"
        RepeatColumns="8" RepeatDirection="Horizontal" OnSelectedIndexChanged="cblWarehouse_SelectedIndexChanged">
</asp:CheckBoxList>

<asp:LinkButton ID="lnkBtnSummary" runat="server" OnClick="lnkBtnSummary_Click"
        Target="_blank">Review Lot Pictures Summary Report</asp:LinkButton>

What I am trying to accomplish is to pass the selected value(s) from cblWarehouse to the summary page "PictureLotFilesSummary.aspx". So I have the following codebehind working.

PicturesLotFiles.aspx.cs
protected void lnkBtnSummary_Click(object sender, System.EventArgs e)
{
    Session["WarehouseSelected"] = "";

    StringBuilder sb = new StringBuilder();
    foreach (ListItem listItem in cblWarehouse.Items)
    {
        if (listItem.Selected)
        {
            sb.Append(listItem.Value);
            sb.Append(", ");             
        }
    }

    if (sb.Length>2)
        sb.Remove(sb.Length - 2, 2);

    Session["WarehouseSelected"] = sb;

    //Response.Write("<SCRIPT language=\"javascript\">open('PicturesLotFilesSummary.aspx','_blank','top=0,left=0,status=yes,resizable=yes,scrollbars=yes');</script>");
    //Response.Redirect("~/PicturesLotFilesSummary.aspx");
}

From my code above I was able to pass the values using Session, but I have not tried QueryString yet. I have commented out the last two line since one of it opens a new pop up window, and the other one simply redirect to the page.

Is there any other way I can try to accomplish my goal? Which is pass the values selected to the summary page and open it in the new tabs instead of new window? Thanks!

joseph.c
  • 146
  • 13
  • Maybe you should try QueryString and check if that way works for you.For open a new tab, check this [answer](https://stackoverflow.com/a/10493957/4092887) or try `c# asp.net open in new tab`. – Mauricio Arias Olave Aug 09 '17 at 19:25
  • @MauricioAriasOlave the link you provided also opens the page in new window for me. I guess I will have to accept that. – joseph.c Aug 09 '17 at 19:29

1 Answers1

1

You can use window.open, but remove all the windows formatting arguments

Response.Write("<SCRIPT language=\"javascript\">open('PicturesLotFilesSummary.aspx','_blank');</script>");

After that it's up to the browser's setting whether it's setup to open links in a new window or a new tab.

If you need to pass sd as an argument it shouldn't be a big deal:

Response.Write("<SCRIPT language=\"javascript\">open('PicturesLotFilesSummary.aspx?sb=" + 
    sb + "','_blank');</script>");
hardkoded
  • 18,915
  • 3
  • 52
  • 64