重要なお知らせ

「教えて! goo」は2025年9月17日(水)をもちまして、サービスを終了いたします。詳細はこちら>

【GOLF me!】初月無料お試し

GridViewを使用して一覧表示
各行のボタンでファイルダウンロード(対象ファイルはExcel)機能を作成しております。

ヘルプ多種多様なWebページを参考に以下の状態まで作成しました。

1.GridViewの一覧表示
2.選択されたボタンの判別
3.隠した列のURLでファイルダウンロード実行

3.の処理で以下のエラーが発生してしまい。困っています。
 『Microsoft JScript 実行時エラー:
Sys.WebForms.PageRequestManagerParserErrorException:
サーバーから受信したメッセージを解析できませんでした。』

有識者の方、よろしくお願いします。

検討違いかもしれませんが、
GridViewのデータ表示時、ボタンにはPOSTBACKするソースが無かった
ように見受けられました。この問題に関係があるのか
判りませんが載せさせていただきます。


環境
OS:XP 言語:C# VS2010 .NET FREM WORK4

・HTML
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridViewhogeList" />
</Triggers>

<ContentTemplate>
<asp:GridView ID="GridViewhogeList" runat="server"
AllowPaging="True"

OnRowCreated="GridViewhogeList_RowCreated"
OnRowCommand="Gridesult_RowOnCommand">

<Columns>
<asp:TemplateField HeaderText="ダウンロード" >
<HeaderStyle Width="60px" />
<ItemStyle Width="60px" HorizontalAlign="center" />
<ItemTemplate>
<asp:Button ID="ButtonToDownLoad" runat="server"
CommandName="Page" Text="出力" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>

・CS
protected void GridResult_RowOnCommand(object sender,
GridViewCommandEventArgs e)
{
// 選択行データを取得
GridViewRow row =
this.GridViewhogeList.Rows[int.Parse(e.CommandArgument.ToString())];

string URL = row.Cells[1].Text.ToString();
string strFileName = System.IO.Path.GetFileName(URL);

// ファイルダウンロード処理
Response.Clear();
Response.ContentType = "application /vnd.ms-excel"; ;
Response.Charset = "";
Response.AddHeader("content-disposition", "attachment;
      filename=" + HttpUtility.UrlEncode("old_" + strFileName));
Response.WriteFile(URL);
  //★Response.Endを実行すると3.のエラーが発生
Response.End()

A 回答 (1件)

<asp:UpdatePanel>でAsp.Net AjaxのUpdatePanelになっているからでは?


トリガボタンが発生させるのは、Ajax Callで、内部的にJavaScriptのコールバックルーチンが呼ばれています。

<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridViewhogeList" />
</Triggers>
<ContentTemplate>


</ContentTemplate>
</asp:UpdatePanel>

を取り去って、通常のPostbackするWebフォームにしてしまえば動作します。
    • good
    • 0
この回答へのお礼

ありがとうございます。勉強になりました。

お礼日時:2011/02/05 09:35

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!