Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 590
  • Last Modified:

net code behind calling window.open

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
stephenwilde
Asked:
stephenwilde
  • 2
1 Solution
 
GuitarRichCommented:
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
 
GuitarRichCommented:
sorry that should be using OnClientClick not AddAttributes
0
 
stephenwildeAuthor Commented:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now