0

I've made a few master pages in visual studio, and then a few implementing pages, and Visual Studio sticks ID attributes onto all of my tags:

<asp:Content ID="Content1" ContentPlaceHolderID="OtherContent" ></asp:Content>

What gives with the IDs? What are they good for? How do I access them from the code behind?

4

1 回答 1

1

在服务器上运行的所有控件都必须具有 ID 属性作为唯一标识符。它们适用于查找子控件并保持控件层次结构到位。如果您有一个文本框位于一个面板中,该面板位于更新面板中,而更新面板位于 WebUserControl 中,而 WebUserControl 位于页面中的 ContentPlaceHolder 中,那么只需要其中一个没有正确的 ID 属性以保持 TextBox 之间的连接和页面。

为了从后面的代码中访问它,您需要runat="server"在此标签上设置属性。

于 2012-06-04T20:41:34.203 回答