Home > Net >  Loginview is used in the master page, the page control is null, please advice
Loginview is used in the master page, the page control is null, please advice

Time:10-01

Such as in the title, use vs2017, this problem bothering me for a long time, suffer from gates, hereby, more kindness, and to give directions, thank you,
Master page:
The
reference
 
& lt; % @ Master Language="c #" AutoEventWireup="true" CodeFile="MasterPage. Master. Cs" Inherits="MasterPage % & gt;"

& lt; ! DOCTYPE html>

& lt; html>
& lt; The head runat="server" & gt;
& lt; Meta HTTP - equiv="content-type" Content="text/HTML. Charset=utf-8 "/& gt;
& lt; title> & lt;/title>
& lt; Asp: ContentPlaceHolder id="head" runat="server" & gt;
& lt;/asp: ContentPlaceHolder>
& lt;/head>
& lt; body>
& lt; The form id="form1" runat="server" & gt;
& lt; Asp: LoginView ID="LoginView1" runat="server" & gt;
& lt; AnonymousTemplate> Hello
& lt; LoggedInTemplate>
& lt; Div>
You have logged
& lt; Asp: ContentPlaceHolder id="ContentPlaceHolder1" runat="server" & gt;
& lt;/asp: ContentPlaceHolder>
& lt;/div>
& lt;/LoggedInTemplate>
& lt;/asp: LoginView>
& lt;/form>
& lt;/body>
& lt;/html>

The child page:
The
reference
 
& lt; % @ Page Title="" Language=" c # "MasterPageFile=" ~/MasterPage. Master "AutoEventWireup=" true "CodeFile=" Default2. Aspx. Cs "Inherits=" Default2 % & gt;"

& lt; Asp: Content ID="Content1" ContentPlaceHolderID="head" Runat="Server" & gt;
& lt;/asp: Content>
& lt; Asp: Content ID="Content2 ContentPlaceHolderID"="ContentPlaceHolder1" Runat="Server" & gt;
& lt; Asp: TextBox ID="TextBox1" runat="server" & gt; & lt;/asp: TextBox>
& lt;/asp: Content>

A page of cs:
The
reference
 
using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. The Web;
Using System. Web. UI.
Using System. Web. UI. WebControls;

Public partial class Default2: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
TextBox1. Text="hello3";
}
}

A running, an error:
The
reference
 
System. NullReferenceException
HResult=0 x80004003
Message=the object reference not set to an instance of an object,
Source=App_Web_basnoeqa
StackTrace:
In Default2. Page_Load (Object sender, EventArgs e) in the C: \ WebSite3 \ WebSite3 \ Default2 aspx. Cs: line 12

Kindly advice, thank you,
  •  Tags:  
  • C#
  • Related