<%@ Page Language="VB" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="false" CodeFile="Page1.aspx.vb" Inherits="Page1" title="Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" />
<asp:Label ID="Label2" runat="server" />
<asp:Label ID="Label3" runat="server" />
<asp:Label ID="Label4" runat="server" />
</asp:Content>
后台代码
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For i = 1 To 3
CType(Me.FindControl("Label" & CStr(i)), Label).Text = i
Next
End Sub
但是在运行的时候找不到Label1, Label2
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
但是