0

I write this coding in C# in my sharepoint project. It works well.

ClientScript.RegisterStartupScript(this.GetType(), "ale", "window.open('DownloadHandler.ashx?fileName=Error.log');", true);

But when I change my coding to this, it no longer works.

ClientScript.RegisterStartupScript(this.GetType(), "ale", string.Format("window.open('DownloadHandler.ashx?fileName={0}')", "Error.log"), true);

What's wrong with my coding?

5
  • 2
    Define "no longer works", please? Commented Dec 27, 2011 at 3:05
  • 4
    I don't know, there's a missing ; at the end of the window.open() statement? Commented Dec 27, 2011 at 3:07
  • 1
    @kevin Missing Semicolon at the end of javascript?? Commented Dec 27, 2011 at 3:08
  • no longer works mean, it does not download the file at all. Commented Dec 27, 2011 at 3:10
  • Ohh Thanks a lot, yes it's the semi colon ; Commented Dec 27, 2011 at 3:11

2 Answers 2

2

There's a missing ; at the end of the window.open() statement:

ClientScript.RegisterStartupScript(
    this.GetType(), 
    "ale", 
    string.Format("window.open('DownloadHandler.ashx?fileName={0}');", "Error.log"),
    true
);
Sign up to request clarification or add additional context in comments.

4 Comments

I'm curious as to why this lack of a semicolon would cause it to stop working, since Javascript has automatic semicolon insertion.
@PeterOlson - I'm not sure, since I was thinking the same thing (minor error in Javascript). Maybe IE throws an error and stops execution if a statement is not ended? I'm wondering the same thing. It was the only problem I saw with the example code.
Script registrar may have other scripts after it which are added together, thus rendering the script in error. This script string is processed by .net before it is executed by javascript.
@TomislavMarkovski - That was my second guess, which was something else was happening that threw the actual on-page script off. Always best to inspect what the browser sees vis-a-vis Javascript.
1

So it's missing a semi colon ; at the end.

ClientScript.RegisterStartupScript(this.GetType(), "ale", string.Format("window.open('DownloadHandler.ashx?fileName={0}');", "Error.log"), true);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.