Problem with Window.open Javascript.

S

Shamin

Hi,

Thanks in advance for answering to my Question. I'm stuck with this
problem and would really appreciate any help.

I have 2 aspx files (Main.aspx and ReportViewer.aspx). Main.aspx has a
datagrid which is populated with list of report names. When the user
click on the name of a report, I display a panel that has a button
which on clicking will run the report. The report will open in
ReportViewer.aspx, This page has a Report Document and
CrystalReportViewer.

I have the Window.open Javascript on Main.aspx which is pasted below.
----------------------
</script>
<script language="JavaScript">

<!--//

function new_window(url) {

link = window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=1010,height=600,left=0,top=0");

}
//-->
</script>
-----------------------

I have the Following code on the Click event of the button in
Main.aspx
------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Session("ReportPath") = mygrid.SelectedItem.Cells(2).Text
Button1.Attributes.Add("onClick",
"new_window('ReportViewer.aspx')")
End Sub
------------------------

I have the Following code in ReportViewer.aspx.
------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Report.Load(Session("ReportPath"))
CrystalReportViewer1.ReportSource = Report
End Sub

------------------------
Here is my Problem. In Main.aspx, when i select a report name and
click the button the first time, I just see the process bar quickly
running from start to end. The report doesn't open. When i click the
button the second time, the report opens fine in a new window. But
then, if i select another report after that and click the button, the
same report opens again instead of opening the new report that i
selected.
How do i resolve this.

Hope i've explained my problem clearly.

Thanks
Shamin
 
G

Guest

Session("ReportPath") = mygrid.SelectedItem.Cells(2).Text
Button1.Attributes.Add("onClick",
"new_window('ReportViewer.aspx')")


That will not work.
You cannot both have a Server On Click and a Client-Side JavaScript for a
button.
In this case because the Client Side OnCLick is being added when the Same
Button is pressed it never gets done.

I think that you want to look at RegisterClientScriptBlock to accomplish the
creation of the NewWindow upon a certain button click if you need the Server
Side button click and a window to open at the same time. Please be advised
however that this is a faulty design as this will most likely get blocked by
popup blockers which will now ship by default on.
 
A

ASP Guy

Hi,

Thanks for the reply and advice. Is there a different way i can
accoomplish this.

Thanks
 
C

Chad Crowder

You could place a literal inside of a script tag, and then populate the
literal from your button click method.

For example, in your html you could do something like....
<script language="javascript">
<asp:Literal id="MyLiteral" runat="server"
EnableViewState="False"></asp:Literal>
</script>

Then, in your button click method...
MyLiteral.Text = "window.open('" & urlvalue & "');"
MyLiteral.EnableViewState = True

You'd have to tweak it a bit to get your window settings and such. I've
found it quite useful - expecially for alert boxes.
- Chad
 
J

Jeff Kanel

Here it is...

Dim PopupScript As String
PopupScript = "<script>popReportWindow('<<someparamvalue>>')</script>"
MyBase.Page.RegisterStartupScript("<<somescriptkey>>", PopupScript)

Rather than writing all the script in the code-behind, create the bulk
of the javascript in the aspx and add a RegisterStartupSCript
reference in code. The script will appear just before the closing
form tag.
 

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

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top