HTML
<body>
<form id="form1" runat="server">
<asp:Button runat="server" ID="a" OnClick="a_Click" Text="apd"/>
</form>
</body>
Код
protected void a_Click(object sender,EventArgs e)
{
Response.Write(((Button)FindControl("a")).Text);
}
Этот код работает нормально.
Однако этот код:
HTML
<%@ Page Title="" Language="C#" MasterPageFile="~/Student/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Student_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Button runat="server" ID="a" OnClick="a_Click" Text="andj"/>
</asp:Content>
Код
protected void a_Click(object sender, EventArgs e)
{
Response.Write(((Button)FindControl("a")).Text);
}
Этот код не работает и FindControl
возвращает Null
- почему так?
Метод FindControl
отлично работает на простой странице, но не работает на мастер-странице?
Идентификатор a
изменен на ctl00_ContentPlaceHolder1_a
- как найти управление?