0

这是我的代码:

String url = "http://blablabla.blablabla.blabla/blabla/bla";

    String html_sonuc;
    WebResponse objResponse;
    WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
    objResponse = objRequest.GetResponse();

    using (StreamReader sr =
           new StreamReader(objResponse.GetResponseStream()))
    {
        html_sonuc = sr.ReadToEnd();
        sr.Close();
    }

    ////////////Script Kodu//////////////
    string script = @"  function layerCek({0}) {
        var features = geojson.read({0});
        var bounds;
        if (features) {
            if (features.constructor != Array) {
                features = [features];
            }
            for (var i = 0; i < features.length; ++i) {
                if (!bounds) {
                    bounds = features[i].geometry.getBounds();
                } else {
                    bounds.extend(features[i].geometry.getBounds());
                }

            }
            vectors.addFeatures(features);
            map.zoomToExtent(bounds);

        } else {
            alert('okuma hatası !');
        }
    }"; 
    /////////////////////////////////////
  string result = string.Format(script, html_sonuc);


    ScriptManager.RegisterClientScriptBlock(
        this.Page, 
        this.Page.GetType(), 
        "whatever", 
        result, 
        true);

我想在 aspx.cs 文件中使用 javascript。但我无法使用此代码。

string result = string.Format(script, html_sonuc); this line,I am taking error.

错误代码:FormatException 未被用户代码处理。

我该如何解决这个问题或者我尝试不同的方法来解决?

4

2 回答 2

1

查看string.Format()文档

您需要指定格式,因此请使用以下内容:

string result = string.Format("Script: {0} - html: {1}", script, html_sonuc);
于 2013-09-10T08:18:31.797 回答
0

您的格式字符串:

string script = @"  function layerCek({0}) {{
    var features = geojson.read({0});
    var bounds;
    if (features) {{
        if (features.constructor != Array) {{
            features = [features];
        }}
        for (var i = 0; i < features.length; ++i) {{
            if (!bounds) {{
                bounds = features[i].geometry.getBounds();
            }} else {{
                bounds.extend(features[i].geometry.getBounds());
            }}

        }}
        vectors.addFeatures(features);
        map.zoomToExtent(bounds);

    }} else {{
        alert('okuma hatası !');
    }}
}}";

{{

于 2013-09-10T08:34:18.123 回答