1

I am using below code to open the new window from server side

 string UserId = "99798";
    string url = "http://www.XYZ.com?Id='"+UserId+"&MatId=12";
    StringBuilder sb = new StringBuilder();
    sb.Append("<script>");
    sb.Append("window.open("+url+", 'my_App', '');");
    sb.Append("</scri");
    sb.Append("pt>");
    Page.RegisterStartupScript("test", sb.ToString());

But it is giving me javascript error

Expected ')'

But everything is working fine when URL = "http://www.google.com";

What is the error? How can I resolve this

1
  • What does the resulting JavaScript look like? Commented May 12, 2011 at 10:52

3 Answers 3

2
string UserId = "99798";
    string url = "http://www.XYZ.com?Id="+UserId+"&MatId=12";
    StringBuilder sb = new StringBuilder();
    sb.Append("<script>");
    sb.Append("window.open('"+url+"', 'my_App', '');");
    sb.Append("</scri");
    sb.Append("pt>");
    Page.RegisterStartupScript("test", sb.ToString());
Sign up to request clarification or add additional context in comments.

1 Comment

And generally it's useful to tell what is wrong with the OP's code, now he can simply copy-paste your code without learning anything.
2

If you are trying to create a querystring after http://www.XYZ.com query string format is

url?key1=value1&key2=value2...&keyn=valuen

2 Comments

Thanks for the response. It was the typo. I am sorry for that. :-( I am little tense you can check here why .. programmers.stackexchange.com/questions/72374/…
ahaha i see.Working on weekends sucks really. Good luck on that /:
0

You should also use (though it isn't the problem, it is a best practice)

sb.Append("<script type='text/javascript'>");

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.