TemplateField に Button を持つ GridView があります。TemplateField によって生成されたボタンの 1 つをクリックすると、マスター ページのコンテンツが表示されますが、実際に読み込んでいるページのコンテンツは表示されません。GridView または GridView を含む div に関連するものの外側にある (デバッグ目的の) OutputLabel もありますが、どちらもありません。
コンテンツページ:
<%@ Page Title="Administration" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Admin.aspx.cs" Inherits="Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainCon" Runat="Server">
<div id="container" class="left-margin">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="CustomGetAllUsers" TypeName="Helper"></asp:ObjectDataSource>
<asp:GridView runat="server" ID="UserGrid" CssClass="UserList" AllowPaging="True" AllowSorting="True" AllowCustomPaging="True" DataSourceID="ObjectDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" style="margin: auto">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Height="50"/>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
<Columns>
<asp:TemplateField runat="server">
<ItemTemplate>
<asp:Button ID="EditButton" runat="server" Text="Rediger" BorderColor="LightBlue" BackColor="LightGray" BorderWidth="3px" BorderStyle="Solid" OnClick="EditButton_Click"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:Label runat="server" ID="OutputLabel" />
</asp:Content>
そして、クリック時に実行されるコード:
protected void EditButton_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
HttpCookie cookie = new HttpCookie("Username", gvr.Cells[2].Text);
Response.Cookies.Add(cookie);
Response.Redirect("~/UserAdmin.aspx");
}