0

我正在使用带有 Ext.Net 框架的 Asp.net。而且我必须使用 Javascript 代码(不是 ext.net 代码)。

默认.aspx 页面:

<asp:UpdatePanel runat="server">

            <ContentTemplate>
                <asp:Button runat="server" Text="tıkla" ID="btnGetir" OnClick="btnGetir_Click" />
............
............

Default.aspx.cs 页面:

 public void btnGetir_Click(object sender, EventArgs e)
    {


        String url = "http://blablablablabla:8080/MeramElektrik2/webresources/entities.layers/GetLayer/1004";

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

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



        ////////////Script Çalıştırma Kodu///////////////////////////
        ScriptManager.RegisterStartupScript(
            this,
            this.GetType(),
            "deneme2",
            "deserialize('" + html_sonuc + "');",
            true);
        /////////////////////////////////////////////////////////////
            txtScript.Text = html_sonuc;
    }

OpenLayerUsers.js 页面:

function deserialize(html_sonuc) { //GEOJSON I, ÇİZİLMİŞ ŞEKLE DÖNÜŞTÜRÜYOR


//var element = document.getElementById('txtScript');
var features = geojson.read(html_sonuc);
//var features = json.read(element.value);
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);
    var plural = (features.length > 1) ? 's' : '';
   //element.value = features.length + ' feature' + plural + ' added'
} else {
  //element.value = 'Bad input';
}

}

结果,反序列化(html_sonuc)函数不起作用。

4

1 回答 1

0

这是简单的测试用例

页面

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Js/jquery-1.8.2.min.js"></script>
    <script>

        Ext.onReady(function () {
        });

        function deserialize(testdt) {
            alert('sonic bumm:' + testdt);
 }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <ext:ResourceManager ID="myrsc" runat="server"></ext:ResourceManager>
    <div>
     <asp:Button runat="server" Text="tıkla" ID="btnGetir" OnClick="btnGetir_Click" />
    </div>
    </form>
</body>
</html>

以及背后的代码;

 protected void btnGetir_Click(object sender, EventArgs e)
    {
        // do something here 
        // and add the client script
        string testdt = "testdata";
        string script = "deserialize('" + testdt + "')";

        myrsc.AddScript(script);
    }
于 2013-12-15T20:29:51.130 回答