Solved

net code behind calling window.open

Posted on 2009-05-08
3
577 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
Comment Utility
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
Comment Utility
sorry that should be using OnClientClick not AddAttributes
0
 

Author Comment

by:stephenwilde
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now