Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

window.open & RegisterClientScriptBlock

Posted on 2006-06-13
6
Medium Priority
?
800 Views
Last Modified: 2008-03-10
Hi,

I have an ASP .NET (1.1) page in C# with a Text Box and a button. The user enters some HTML code into the text box and presses the button for a preview. The server side code saves the entered HTML to an *.htm file and uses RegisterClientScriptBlock to have the client browser open the preview file in a new window.

private void btnPreview_Click(object sender, System.EventArgs e)
{
   string               html         = "";
   string               filename      = "";
   System.IO.StreamWriter   streamWriter   = null;

   html   = this.txtScript.Text; // This is the text box in which the user entered some HTML code

   try
   {
      filename   = this.Server.MapPath("ScriptPreview.htm");

      streamWriter   = System.IO.File.CreateText(filename);
      streamWriter.Write(html);
      streamWriter.Close();

      this.RegisterClientScriptBlock("Preview", "<SCRIPT LANGUAGE=\"javascript\">window.open(\"Preview.htm\");</SCRIPT>");
   }
   catch
   {
   }
}

I know the code works because when viewing the HTML source of the resulting page, the newly inserted script is visible but has no effect and no window is opened.

Any ideas?

Thanks,

Khan
0
Comment
Question by:raheelasadkhan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Author Comment

by:raheelasadkhan
ID: 16893017
I tried replacing the following line:

this.RegisterClientScriptBlock("Preview", "<SCRIPT LANGUAGE=\"javascript\">window.open(\"Preview.htm\");</SCRIPT>");
  with
this.RegisterClientScriptBlock("Alert", "<SCRIPT LANGUAGE=\"javascript\">alert(\"sdfsdfsdf\");</SCRIPT>");

And this works fine!!!

What am I doing wrong with the original statement.
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16893021
Hi,
The above code opens the .htm page for me.
Do u want to open the dialog box or new page?

--pradeep
0
 
LVL 14

Expert Comment

by:existenz2
ID: 16894351
The path to Preview.htm might be incorrect

An additional note:

For security reasons I would suggest you to use a literal control in a default not-editable page to fill the created html page in. A lot safer (+ more controlable).
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:raheelasadkhan
ID: 16897533
pradeepsudharsan:
Hmmm... I tried it on two different machines and did not work on either. I had considered a Dialog but that wouldn't work with netscape right. I need this to be compatible with at least IE and Netscape and preferably FireFox as well.

existenz2:
I verified the path to Preview.htm by viewing the source of the generated page and copy-pasting the url in the browser.
Regarding the literal control, I'm not sure what you mean. Please explain.
0
 
LVL 14

Accepted Solution

by:
existenz2 earned 2000 total points
ID: 16897815
A literal control is a control in which you can include through you code behind dynamicly any form of html. Basicly it's just a empty placeholder for pure html. By creating pages from the html people have provided you allow them to possibly ad dangerous code which could do harm to your system. Using a literal control allows you to control this much better.
0
 

Author Comment

by:raheelasadkhan
ID: 16913022
I tried the literal control and am able to display the preview on the same page. This is nice but I have one question. Since you have already solved my primary problem, it's fair to post the new question as a new post. I'm accepting this answer and opening a new question. If you're interested, please check out (http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21887812.html).
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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