
前提・実現したいこと
いつもお世話になっております。
DataPager付のListViewを持つWebForm1とLabelを持つWebForm2があります。
WebForm1のListViewはボタンを持ち、PostBackUrlにはWebForm2を設定しています。
WebForm1のListViewのボタンを押し、WebForm2へ遷移後、ブラウザ(Firefox)の戻るボタンを押し、WebForm1へ戻ります。
その後、WebForm1のDataPagerで任意のページを選択するとWebForm2を参照してしまいエラーが発生します。
なお、Internet ExplolerとChromeでは発生しません。また、ローカルでデバッグ時にも発生しません。
発生している問題・エラーメッセージ
'/FindControlTest' アプリケーションでサーバー エラーが発生しました。 ランタイム エラー 説明: サーバーでアプリケーション エラーが発生しました。このアプリケーションの現在のカスタム エラー設定では、セキュリティ上の理由により、アプリケーション エラーの詳細をリモート表示できません。ただし、ローカル サーバー コンピューターで実行されているブラウザーで表示することはできます。 詳細: このエラー メッセージの詳細をリモート コンピューターで表示できるようにするには、現在の Web アプリケーションのルート ディレクトリにある "web.config" 構成ファイル内に、<customErrors> タグを作成してください。その後で、この <customErrors> タグで "mode" 属性を "off" に設定してください。 <!-- Web.Config 構成ファイル --> <configuration> <system.web> <customErrors mode="Off"/> </system.web> </configuration> メモ: 現在表示されているエラー ページをカスタム エラー ページに変更するには、アプリケーションの <customErrors> 構成タグの "defaultRedirect" 属性をカスタム エラー ページ URL に置き換えます。 <!-- Web.Config 構成ファイル --> <configuration> <system.web> <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/> </system.web> </configuration>
該当のソースコード
WebForm1
aspx
1<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="FindControlTest.WebForm1" %> 2 3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5<html xmlns="http://www.w3.org/1999/xhtml"> 6<head runat="server"> 7 <title></title> 8</head> 9<body> 10 <form id="form1" runat="server"> 11 <div> 12 <asp:ListView ID="ListView1" runat="server" DataKeyNames="ID" 13 DataSourceID="SqlDataSource1"> 14 <AlternatingItemTemplate> 15 <tr style=""> 16 <td> 17 <asp:Button ID="Button1" runat="server" Text="ジャンプ" CommandName="Select" PostBackUrl="WebForm2.aspx" /> 18 <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' /> 19 </td> 20 </tr> 21 </AlternatingItemTemplate> 22 <EditItemTemplate> 23 <tr style=""> 24 <td> 25 <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="更新" /> 26 <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 27 Text="キャンセル" /> 28 </td> 29 <td> 30 <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' /> 31 </td> 32 </tr> 33 </EditItemTemplate> 34 <EmptyDataTemplate> 35 <table runat="server" style=""> 36 <tr> 37 <td> 38 データは返されませんでした。</td> 39 </tr> 40 </table> 41 </EmptyDataTemplate> 42 <InsertItemTemplate> 43 <tr style=""> 44 <td> 45 <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="挿入" /> 46 <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="クリア" /> 47 </td> 48 <td> 49 <asp:TextBox ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>' /> 50 </td> 51 </tr> 52 </InsertItemTemplate> 53 <ItemTemplate> 54 <tr style=""> 55 <td> 56 <asp:Button ID="Button1" runat="server" Text="ジャンプ" CommandName="Select" PostBackUrl="WebForm2.aspx" /> 57 <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' /> 58 </td> 59 </tr> 60 </ItemTemplate> 61 <LayoutTemplate> 62 <table runat="server"> 63 <tr runat="server"> 64 <td runat="server"> 65 <table ID="itemPlaceholderContainer" runat="server" border="0" style=""> 66 <tr runat="server" style=""> 67 <th runat="server"> 68 </th> 69 <th runat="server"> 70 ID</th> 71 </tr> 72 <tr ID="itemPlaceholder" runat="server"> 73 </tr> 74 </table> 75 </td> 76 </tr> 77 <tr runat="server"> 78 <td runat="server" style=""> 79 <asp:DataPager ID="DataPager1" runat="server"> 80 <Fields> 81 <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 82 ShowNextPageButton="False" ShowPreviousPageButton="False" /> 83 <asp:NumericPagerField /> 84 <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" 85 ShowNextPageButton="False" ShowPreviousPageButton="False" /> 86 </Fields> 87 </asp:DataPager> 88 </td> 89 </tr> 90 </table> 91 </LayoutTemplate> 92 <SelectedItemTemplate> 93 <tr style=""> 94 <td> 95 <asp:Button ID="Button1" runat="server" Text="ジャンプ" CommandName="Select" PostBackUrl="WebForm2.aspx" /> 96 <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' /> 97 </td> 98 </tr> 99 </SelectedItemTemplate> 100 </asp:ListView> 101 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 102 ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 103 ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 104 SelectCommand="SELECT "ID" FROM "TABLE1""> 105 </asp:SqlDataSource> 106 </div> 107 </form> 108</body> 109</html>
C#
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Web; 5using System.Web.UI; 6using System.Web.UI.WebControls; 7 8namespace FindControlTest 9{ 10 public partial class WebForm1 : System.Web.UI.Page 11 { 12 protected void Page_Load(object sender, EventArgs e) 13 { 14 15 } 16 } 17}
WebForm2
aspx
1<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="FindControlTest.WebForm2" %> 2 3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5<html xmlns="http://www.w3.org/1999/xhtml"> 6<head runat="server"> 7 <title></title> 8</head> 9<body> 10 <form id="form1" runat="server"> 11 <div> 12 <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 13 </div> 14 </form> 15</body> 16</html>
C#
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Web; 5using System.Web.UI; 6using System.Web.UI.WebControls; 7 8namespace FindControlTest 9{ 10 public partial class WebForm2 : System.Web.UI.Page 11 { 12 protected void Page_Load(object sender, EventArgs e) 13 { 14 if (!IsPostBack) 15 { 16 if (Page.PreviousPage != null) 17 { 18 ListView listview = (ListView)Page.PreviousPage.FindControl("ListView1"); 19 Label1.Text = listview.SelectedDataKey[0].ToString(); 20 } 21 } 22 } 23 } 24}
試したこと
Internet Exploler、Chromeでは発生しませんでした。
補足情報(FW/ツールのバージョンなど)
Oracle: Oracle 11g
サーバーOS:Windows Server 2012
クライアントOS:Windows7
.NET:4.0
サーバーIIS:8.0
クライアントIIS:10.0 Express
Visual Studio:2015 Express for Web
追記(Web.config編集後のエラー)
'/FindControlTest' アプリケーションでサーバー エラーが発生しました。 オブジェクト参照がオブジェクト インスタンスに設定されていません。 説明: 現在の Web 要求を実行中に、ハンドルされていない例外が発生しました。エラーに関する詳細および例外の発生場所については、スタック トレースを参照してください。 例外の詳細: System.NullReferenceException: オブジェクト参照がオブジェクト インスタンスに設定されていません。 ソース エラー: 現在の Web 要求の実行中にハンドルされていない例外が生成されました。障害の原因および発生場所に関する情報については、下の例外スタック トレースを使って確認できます。 スタック トレース: [NullReferenceException: オブジェクト参照がオブジェクト インスタンスに設定されていません。] FindControlTest.WebForm2.Page_Load(Object sender, EventArgs e) +165 System.Web.UI.Control.LoadRecursive() +70 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3177 バージョン情報: Microsoft .NET Framework バージョン:4.0.30319; ASP.NET バージョン:4.0.30319.17929




回答2件
あなたの回答
tips
プレビュー