471,074 Members | 1,430 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,074 software developers and data experts.

Problem with Window.open Javascript.

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,direc tories=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
Nov 18 '05 #1
6 2485
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.


"Shamin" <sh******@hotmail.com> wrote in message
news:44**************************@posting.google.c om...
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,direc tories=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



Nov 18 '05 #2
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.


"Shamin" <sh******@hotmail.com> wrote in message
news:44**************************@posting.google.c om...
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,direc tories=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



Nov 18 '05 #3

Hi,

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

Thanks


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4

Hi,

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

Thanks


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #5
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

"ASP Guy" <my****@mymail.com> wrote in message
news:uw**************@TK2MSFTNGP09.phx.gbl...

Hi,

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

Thanks


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #6
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.
sh******@hotmail.com (Shamin) wrote in message news:<44**************************@posting.google. com>...
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,direc tories=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

Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Marco | last post: by
2 posts views Thread by Christian Kusenbach | last post: by
4 posts views Thread by Anna Quick | last post: by
1 post views Thread by Julius Mong | last post: by
2 posts views Thread by Samir Pandey | last post: by
4 posts views Thread by VR | last post: by
18 posts views Thread by len.hartley | last post: by
5 posts views Thread by althafexcel | last post: by
2 posts views Thread by swethak | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.