Open Report Results in New Window

Discussion in 'ASP .Net' started by Mel, Jul 22, 2008.

  1. Mel

    Mel Guest

    I have a web page where the user enters up to 2 inputs and then clicks
    the Submit to run the report. On Submit_Click I want to create the
    SQL string, based on their inputs, and pass that SQL string to a new
    window which will show the report results. How do I create the SQL
    string and open the results in a new window?

    Here is my code so far, however, it does not open in new window
    (Using Asp.net 2.0, Visual Basic.NET, Visual Studio 2005 Pro, WinXP SP
    2):
    Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As
    System.EventArgs)
    Dim strRecInv As String
    If Trim(txtItem.Text.ToString) = "" And
    Trim(txtItemDesc.Text.ToString) = "" Then
    Exit Sub
    End If

    strRecInv = "SELECT [Whs],[Item],[Item Desc],[Qty Available] FROM
    [vWhsItemAvailabilty] WHERE ([Whs Desc] <> '')"

    If txtItem.Text.ToString <> "" Then
    strRecInv = strRecInv & " AND ([Item] LIKE '%" &
    txtItem.Text.ToString & "%')"
    End If

    If txtItemDesc.Text.ToString <> "" Then
    strRecInv = strRecInv & " AND ([Item Desc] LIKE '%" &
    txtItemDesc.Text.ToString & "%')"
    End If

    Session("SQLQuery") = strRecInv & " ORDER BY [Whs],[Item Desc]"
    Response.Redirect("~/trackresults.aspx") 'This cannot be used to open
    in new window. Other ideas?
    End Sub

    'TrackResults.aspx Page_Load
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load
    'by passing the SQL String to this page I can use this same page to
    show any report results from the Sales database on SQLServer01.
    If Session("SQLQuery") Is Nothing Then
    Else
    Dim conInv As New
    SqlConnection("server=SQLServer01;database=Sales;Integrated
    Security=SSPI")
    Dim comInv As New SqlCommand(Session("SQLQuery"), conInv)

    'open database and show results in GridView
    conInv.Open()
    gvResults.DataSource = comInv.ExecuteReader
    gvResults.DataBind()
    conInv.Close()
    Session("SQLQuery") = Nothing
    End If
    End Sub
     
    Mel, Jul 22, 2008
    #1
    1. Advertising

  2. Mel

    bruce barker Guest

    server code can not open a new window. you should use javascript to change
    the form target to a new window name ("_blank" will do).

    -- bruce (sqlwork.com)


    "Mel" wrote:

    > I have a web page where the user enters up to 2 inputs and then clicks
    > the Submit to run the report. On Submit_Click I want to create the
    > SQL string, based on their inputs, and pass that SQL string to a new
    > window which will show the report results. How do I create the SQL
    > string and open the results in a new window?
    >
    > Here is my code so far, however, it does not open in new window
    > (Using Asp.net 2.0, Visual Basic.NET, Visual Studio 2005 Pro, WinXP SP
    > 2):
    > Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs)
    > Dim strRecInv As String
    > If Trim(txtItem.Text.ToString) = "" And
    > Trim(txtItemDesc.Text.ToString) = "" Then
    > Exit Sub
    > End If
    >
    > strRecInv = "SELECT [Whs],[Item],[Item Desc],[Qty Available] FROM
    > [vWhsItemAvailabilty] WHERE ([Whs Desc] <> '')"
    >
    > If txtItem.Text.ToString <> "" Then
    > strRecInv = strRecInv & " AND ([Item] LIKE '%" &
    > txtItem.Text.ToString & "%')"
    > End If
    >
    > If txtItemDesc.Text.ToString <> "" Then
    > strRecInv = strRecInv & " AND ([Item Desc] LIKE '%" &
    > txtItemDesc.Text.ToString & "%')"
    > End If
    >
    > Session("SQLQuery") = strRecInv & " ORDER BY [Whs],[Item Desc]"
    > Response.Redirect("~/trackresults.aspx") 'This cannot be used to open
    > in new window. Other ideas?
    > End Sub
    >
    > 'TrackResults.aspx Page_Load
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    > 'by passing the SQL String to this page I can use this same page to
    > show any report results from the Sales database on SQLServer01.
    > If Session("SQLQuery") Is Nothing Then
    > Else
    > Dim conInv As New
    > SqlConnection("server=SQLServer01;database=Sales;Integrated
    > Security=SSPI")
    > Dim comInv As New SqlCommand(Session("SQLQuery"), conInv)
    >
    > 'open database and show results in GridView
    > conInv.Open()
    > gvResults.DataSource = comInv.ExecuteReader
    > gvResults.DataBind()
    > conInv.Close()
    > Session("SQLQuery") = Nothing
    > End If
    > End Sub
    >
     
    bruce barker, Jul 22, 2008
    #2
    1. Advertising

  3. Mel

    Mel Guest

    On Jul 22, 11:04 am, bruce barker
    <> wrote:
    > server code can not open a new window. you should use javascript to change
    > the form target to a new window name ("_blank" will do).
    >
    > -- bruce (sqlwork.com)
    >
    > "Mel" wrote:
    > > I have a web page where the user enters up to 2 inputs and then clicks
    > > the Submit to run the report. On Submit_Click I want to create the
    > > SQL string, based on their inputs, and pass that SQL string to a new
    > > window which will show the report results. How do I create the SQL
    > > string and open the results in a new window?

    >
    > > Here is my code so far, however, it does not open in new window
    > > (Using Asp.net 2.0, Visual Basic.NET, Visual Studio 2005 Pro, WinXP SP
    > > 2):
    > > Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As
    > > System.EventArgs)
    > > Dim strRecInv As String
    > > If Trim(txtItem.Text.ToString) = "" And
    > > Trim(txtItemDesc.Text.ToString) = "" Then
    > > Exit Sub
    > > End If

    >
    > > strRecInv = "SELECT [Whs],[Item],[Item Desc],[Qty Available] FROM
    > > [vWhsItemAvailabilty] WHERE ([Whs Desc] <> '')"

    >
    > > If txtItem.Text.ToString <> "" Then
    > > strRecInv = strRecInv & " AND ([Item] LIKE '%" &
    > > txtItem.Text.ToString & "%')"
    > > End If

    >
    > > If txtItemDesc.Text.ToString <> "" Then
    > > strRecInv = strRecInv & " AND ([Item Desc] LIKE '%" &
    > > txtItemDesc.Text.ToString & "%')"
    > > End If

    >
    > > Session("SQLQuery") = strRecInv & " ORDER BY [Whs],[Item Desc]"
    > > Response.Redirect("~/trackresults.aspx") 'This cannot be used to open
    > > in new window. Other ideas?
    > > End Sub

    >
    > > 'TrackResults.aspx Page_Load
    > > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > > System.EventArgs) Handles Me.Load
    > > 'by passing the SQL String to this page I can use this same page to
    > > show any report results from the Sales database on SQLServer01.
    > > If Session("SQLQuery") Is Nothing Then
    > > Else
    > > Dim conInv As New
    > > SqlConnection("server=SQLServer01;database=Sales;Integrated
    > > Security=SSPI")
    > > Dim comInv As New SqlCommand(Session("SQLQuery"), conInv)

    >
    > > 'open database and show results in GridView
    > > conInv.Open()
    > > gvResults.DataSource = comInv.ExecuteReader
    > > gvResults.DataBind()
    > > conInv.Close()
    > > Session("SQLQuery") = Nothing
    > > End If
    > > End Sub


    Okay but I am not very familiar with Javascript. Can you provide a
    quick example of how to set the target of the form? Maybe you could
    direct me where would I place the Javascript that would be very
    helpful. My results page has a MasterPageFile and Content sections.
    Here is the TrackResults.aspx Code.

    ---------------------------------------------------------------------------
    <%@ Page Language="VB" MasterPageFile="~/BMQweb.master"
    AutoEventWireup="false" CodeFile="TrackResults.aspx.vb"
    Inherits="TrackResults" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
    Runat="Server">
    <table id="tblResults" style="width: 100%; font-family: Verdana;
    font-size: small;">
    <caption>
    <asp:Label ID="lblTitle" runat="server" Font-Bold="True"
    Font-Size="Large"></asp:Label></caption>
    <tr>
    <td style="width: 100%">
    <asp:GridView ID="gvResults" runat="server">
    <FooterStyle Wrap="False" />
    <EmptyDataRowStyle Wrap="False" />
    <RowStyle Wrap="False" />
    <EditRowStyle Wrap="False" />
    <SelectedRowStyle Wrap="False" />
    <PagerStyle Wrap="False" />
    <HeaderStyle Wrap="False" />
    <AlternatingRowStyle Wrap="False" />
    </asp:GridView>
    </td>
    </tr>
    </table>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2"
    Runat="Server">
    </asp:Content>
    ---------------------------------------------------------------------------
     
    Mel, Jul 22, 2008
    #3
  4. Mel

    Mel Guest

    On Jul 22, 11:36 am, Mel <> wrote:
    > On Jul 22, 11:04 am, bruce barker
    >
    >
    >
    > <> wrote:
    > > server code can not open a new window. you should use javascript to change
    > > the form target to a new window name ("_blank" will do).

    >
    > > -- bruce (sqlwork.com)

    >
    > > "Mel" wrote:
    > > > I have a web page where the user enters up to 2 inputs and then clicks
    > > > the Submit to run the report. On Submit_Click I want to create the
    > > > SQL string, based on their inputs, and pass that SQL string to a new
    > > > window which will show the report results. How do I create the SQL
    > > > string and open the results in a new window?

    >
    > > > Here is my code so far, however, it does not open in new window
    > > > (Using Asp.net 2.0, Visual Basic.NET, Visual Studio 2005 Pro, WinXP SP
    > > > 2):
    > > > Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As
    > > > System.EventArgs)
    > > > Dim strRecInv As String
    > > > If Trim(txtItem.Text.ToString) = "" And
    > > > Trim(txtItemDesc.Text.ToString) = "" Then
    > > > Exit Sub
    > > > End If

    >
    > > > strRecInv = "SELECT [Whs],[Item],[Item Desc],[Qty Available] FROM
    > > > [vWhsItemAvailabilty] WHERE ([Whs Desc] <> '')"

    >
    > > > If txtItem.Text.ToString <> "" Then
    > > > strRecInv = strRecInv & " AND ([Item] LIKE '%" &
    > > > txtItem.Text.ToString & "%')"
    > > > End If

    >
    > > > If txtItemDesc.Text.ToString <> "" Then
    > > > strRecInv = strRecInv & " AND ([Item Desc] LIKE '%" &
    > > > txtItemDesc.Text.ToString & "%')"
    > > > End If

    >
    > > > Session("SQLQuery") = strRecInv & " ORDER BY [Whs],[Item Desc]"
    > > > Response.Redirect("~/trackresults.aspx") 'This cannot be used to open
    > > > in new window. Other ideas?
    > > > End Sub

    >
    > > > 'TrackResults.aspx Page_Load
    > > > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > > > System.EventArgs) Handles Me.Load
    > > > 'by passing the SQL String to this page I can use this same page to
    > > > show any report results from the Sales database on SQLServer01.
    > > > If Session("SQLQuery") Is Nothing Then
    > > > Else
    > > > Dim conInv As New
    > > > SqlConnection("server=SQLServer01;database=Sales;Integrated
    > > > Security=SSPI")
    > > > Dim comInv As New SqlCommand(Session("SQLQuery"), conInv)

    >
    > > > 'open database and show results in GridView
    > > > conInv.Open()
    > > > gvResults.DataSource = comInv.ExecuteReader
    > > > gvResults.DataBind()
    > > > conInv.Close()
    > > > Session("SQLQuery") = Nothing
    > > > End If
    > > > End Sub

    >
    > Okay but I am not very familiar with Javascript. Can you provide a
    > quick example of how to set the target of the form? Maybe you could
    > direct me where would I place the Javascript that would be very
    > helpful. My results page has a MasterPageFile and Content sections.
    > Here is the TrackResults.aspx Code.
    >
    > ---------------------------------------------------------------------------
    > <%@ Page Language="VB" MasterPageFile="~/BMQweb.master"
    > AutoEventWireup="false" CodeFile="TrackResults.aspx.vb"
    > Inherits="TrackResults" %>
    > <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
    > Runat="Server">
    > <table id="tblResults" style="width: 100%; font-family: Verdana;
    > font-size: small;">
    > <caption>
    > <asp:Label ID="lblTitle" runat="server" Font-Bold="True"
    > Font-Size="Large"></asp:Label></caption>
    > <tr>
    > <td style="width: 100%">
    > <asp:GridView ID="gvResults" runat="server">
    > <FooterStyle Wrap="False" />
    > <EmptyDataRowStyle Wrap="False" />
    > <RowStyle Wrap="False" />
    > <EditRowStyle Wrap="False" />
    > <SelectedRowStyle Wrap="False" />
    > <PagerStyle Wrap="False" />
    > <HeaderStyle Wrap="False" />
    > <AlternatingRowStyle Wrap="False" />
    > </asp:GridView>
    > </td>
    > </tr>
    > </table>
    > </asp:Content>
    > <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2"
    > Runat="Server">
    > </asp:Content>
    > ---------------------------------------------------------------------------


    Resolved this issue. I removed the Response.Redirect line and added
    this line at the end of my cmdSubmit_Click (parent page) code:

    ScriptManager.RegisterStartupScript(Me, GetType(String),
    "OpenWindowScript", "window.open('trackresults.aspx')", True)

    Thanks y'all!
     
    Mel, Jul 23, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cheryl
    Replies:
    2
    Views:
    18,084
    Cheryl
    Nov 12, 2003
  2. Gordon
    Replies:
    3
    Views:
    323
    Steven Burn
    Apr 16, 2004
  3. PC HUA
    Replies:
    2
    Views:
    436
    PC HUA
    May 19, 2004
  4. Berlin  Brown

    Selection; open popup or open a new window

    Berlin Brown, Jun 26, 2006, in forum: Javascript
    Replies:
    0
    Views:
    124
    Berlin Brown
    Jun 26, 2006
  5. Replies:
    1
    Views:
    253
Loading...

Share This Page