Open Report Results in New Window


M

Mel

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
 
Ad

Advertisements

B

bruce barker

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)
 
M

Mel

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 said:
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>
---------------------------------------------------------------------------
 
Ad

Advertisements

M

Mel

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 said:
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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top