0

私の ASP.NET ページでは、asp:UpdatePanel 内で Google ビジュアライゼーション チャートを使用しています。ユーザーが 2 つの asp:DropDownLists から見たいグラフを選択すると、C# コードが JavaScript を生成し、ScriptManager.RegisterStartipScript(...) を呼び出します。ページが最初に読み込まれると、最初のデフォルト チャート (つまり、RegisterStartupScript への最初の呼び出し) が機能し、View Source から JavaScript を表示できます。空白のグラフが表示されるのはポストバックのみであり、[ソースの表示] に移動すると、ページは新しい JavaScript を受信せず、最初のページの読み込みから古いデフォルトの JavaScript が残っています。これが奇妙な動作です。まったく同じコードを使用し、Google Chart コードを alert(...); に置き換えた場合。その後、毎回 alert() が発生し、ソースを表示するとスクリプトが表示されます。私'ここに。以下は私のコードであり、助けていただければ幸いです。他の人にこれを見てもらい、私たちは皆困惑しています。参考までに: すべての UpdatePanels と関連項目 (ScriptManager と UpdateProgress) を削除して ClientScript.RegisterStartupScript() を使用すると、すべてが正常に機能し、ページに新しい JavaScript コードが表示され、新しいチャートが正常に表示されます。

<asp:ScriptManager ID="ScriptMgr" runat="server" />

<asp:UpdatePanel ID="UpdatePanelData" runat="server">
    <ContentTemplate> 
        <p>
            <asp:DropDownList ID="PlotList" runat="server" AutoPostBack="true" Width="500px" 
                onselectedindexchanged="PlotList_SelectedIndexChanged"></asp:DropDownList>
            <asp:DropDownList ID="RangeList" runat="server" Width="125px" 
                style="float:right;" AutoPostBack="True" 
                onselectedindexchanged="RangeList_SelectedIndexChanged">
            </asp:DropDownList>
            <br />
            <asp:Label ID="PlotDescription" runat="server" Width="100%"></asp:Label> 
        </p>
        <div id="chart_material" class="GoogleChart" style="width:100%;height:450px;"></div>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="RangeList" EventName="SelectedIndexChanged" />
        <asp:AsyncPostBackTrigger ControlID="PlotList" EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel>

 <asp:UpdateProgress ID="UpdateProgressData" runat="server" DisplayAfter="500">
    <ProgressTemplate>
        <div class="LoadingPanel">
            <asp:Image ID="LoadingImage" runat="server" ImageUrl="~/Images/loading_2.gif" AlternateText="Loading ..." ToolTip="Loading ..." style="padding: 10px;position:fixed;top:45%;left:50%;" />
        </div>
    </ProgressTemplate>
</asp:UpdateProgress>

私の C# コードは次のようになります。関数 DisplayPlot は 2 つの DropDownList イベントから呼び出され、各リストは「コントロール」として渡されます。

private void DisplayPlot(Control control)
    {
        PlotInformation Plot = new PlotInformation(ChartDivID);

        double Range = Convert.ToDouble(RangeList.SelectedValue);

        string JavaScript = Plot.GetPlotScript(PlotList.SelectedItem.Text, Range);

        PlotDescription.Text = Plot.GetDataPlotDescription(PlotList.SelectedItem.Text);

        //string TestScript = "<script type=\"text/javascript\">\n\talert('" + PlotList.SelectedItem.Text + "');\n</script>";

        ScriptManager.RegisterStartupScript(control, control.GetType(), ScriptKey, JavaScript, false);
        //ScriptManager.RegisterStartupScript(control, this.GetType(), ScriptKey, JavaScript, false);

        //if (!ClientScript.IsStartupScriptRegistered(ScriptKey))
        //    ClientScript.RegisterStartupScript(this.GetType(), ScriptKey, JavaScript);
    }
4

1 に答える 1