Hope someone can help me with this problem. I'm using VS.2005 ASP.NET/VB.NET along with the latest release of AJAX for ASP.NET.
Goal: When the user clicks on an ASP.NET button in an AJAX update panel I do a number of things in the code behind that update the page via AJAX. This portion is working fine but now I have a new requirement.
When the user clicks on the same button I also need to open up a new browser window that points to a dynamically generated (meaning the URL is different each time) PDF.
The problem I'm running into is I can't find a way to use response.write (which w/o AJAX would work) while also using AJAX and I'm not too familiar with JavaScript. I know how to open a new window using JavaScript but how do I pass the dynamically created URL
from the code behind to the JavaScript.
I also tried the following code which works w/o and AJAX Update panel but stops working when I add an AJAX update panel
Dim strURL As String = "http://mysite.com?Test=3243243"
Dim jScript As String
jScript = "<script>window.open ('" & strURL & "','_blank');</script>"
Page.RegisterClientScriptBlock("keyBusinessNetworth", jScript)
the reason it doesn;t work is because on a partial postback the client script does not get written to the page and fired. What you could try and do, and this will only work if the page which needs to be opened does not depend on values set durring the partial
postback, and that is to create a web services, wire up the javascript, then onclick of the button call the web service and return the page to be opened, and then open the page.
argono
0 Points
2 Posts
Open new browser window server side while using AJAX Update panel
Aug 07, 2007 05:25 PM|LINK
Hope someone can help me with this problem. I'm using VS.2005 ASP.NET/VB.NET along with the latest release of AJAX for ASP.NET.
Goal: When the user clicks on an ASP.NET button in an AJAX update panel I do a number of things in the code behind that update the page via AJAX. This portion is working fine but now I have a new requirement.
When the user clicks on the same button I also need to open up a new browser window that points to a dynamically generated (meaning the URL is different each time) PDF.
For example I would need to open something like 'http://www.test.com/mypage.aspx?ApplicantID=356235&Type=JobApplication
The problem I'm running into is I can't find a way to use response.write (which w/o AJAX would work) while also using AJAX and I'm not too familiar with JavaScript. I know how to open a new window using JavaScript but how do I pass the dynamically created URL from the code behind to the JavaScript.
I also tried the following code which works w/o and AJAX Update panel but stops working when I add an AJAX update panel
Dim strURL As String = "http://mysite.com?Test=3243243"
Dim jScript As String
jScript = "<script>window.open ('" & strURL & "','_blank');</script>"
Page.RegisterClientScriptBlock("keyBusinessNetworth", jScript)
Is there any other way to do this?
Thanks in advance for any help.
aquillin
Participant
1465 Points
268 Posts
Re: Open new browser window server side while using AJAX Update panel
Aug 07, 2007 06:28 PM|LINK
the reason it doesn;t work is because on a partial postback the client script does not get written to the page and fired. What you could try and do, and this will only work if the page which needs to be opened does not depend on values set durring the partial postback, and that is to create a web services, wire up the javascript, then onclick of the button call the web service and return the page to be opened, and then open the page.
This video can help to do this.
http://www.asp.net/learn/ajax-videos/video-82.aspx
-Alan
gt1329a
All-Star
15377 Points
2501 Posts
ASPInsiders
MVP
Re: Open new browser window server side while using AJAX Update panel
Aug 07, 2007 08:45 PM|LINK
Use ScriptManager.RegisterStartupScript()
A guide to combining jQuery and ASP.NET: jQuery for the ASP.NET developer
argono
0 Points
2 Posts
Re: Open new browser window server side while using AJAX Update panel
Aug 08, 2007 07:01 PM|LINK
Here's the code that works (provided from http://vbcity.com).
Dim jScript As String jScript = String.Format("window.open('{0}', '_blank');", sURL)ScriptManager.RegisterClientScriptBlock(
Me, GetType(Page), "DoPDFOped", jScript, True)Thanks everyone for the help
Mhorkpheus
Member
2 Points
1 Post
Re: Open new browser window server side while using AJAX Update panel
Feb 11, 2013 07:29 PM|LINK
Exelent! it works!!
Thanks a lot!!!!!!