开发者

Formatter URL Javascript error

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


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());


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

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


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜