Solved

net code behind calling window.open

Posted on 2009-05-08
3
579 Views
Last Modified: 2013-12-17
Using .net c# and code behind on button click gets the url from a database and tries to call javascript with variable found and open new web browser window - but code fails as no window created and error message

Error in sys.webforms.pagerequestmanagerparserexception - the message from the server could not be parsed error parsing near <script type='text/

Cannot use aspx page as dont know vlaue in that page only in code behind

Any help please!

// addresess from database call           
 string cAddress = "rgl group so51 6al";
string cUrl = "http://maps.google.co.uk/maps?ie=UTF-8&hl=en&tab=wl&q=" + cAddress;
string cScript = "<script  type='text/javascript'> window.open('" + cUrl + "');</script>";
 Response.Write(cScript);

Open in new window

0
Comment
Question by:stephenwilde
  • 2
3 Comments
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24334239
You could write a method in the code behind to get the Url from the database and then put that into the aspx page using AddAttributes
<asp:Button runat="Server" id="openButton" text="Open"></asp:Button>

In Page_Load:
 
string cAddress = "rgl group so51 6al";
string cUrl = "http://maps.google.co.uk/maps?ie=UTF-8&hl=en&tab=wl&q=" + cAddress;
openButton.OnClientClick = "javascript:window.Open("javascript:window.open('" + cUrl + "')";

Open in new window

0
 
LVL 12

Accepted Solution

by:
GuitarRich earned 500 total points
ID: 24334243
sorry that should be using OnClientClick not AddAttributes
0
 

Author Comment

by:stephenwilde
ID: 24334503
Thanks for yor quick replies

In page load the record required is not known and it is an ajax page so not sure if page event is fired again as in ajax panel

Rgds
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question