By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,262 Members | 2,664 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,262 IT Pros & Developers. It's quick & easy.

Problem with Window.open Javascript.

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a

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

P: n/a

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

P: n/a
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

P: n/a
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.