获取“对象引用未设置为对象的实例”异常

我有两个aspx页面webfrom1.aspx和webform2.aspx。在webform1中,我有两个文本框,我想将文本框数据(由用户输入)发送到webform2。我已经使用查询字符串方法。 我正在例外 字符串文本=((TextBox)lastOne.FindControl(“ MAIL”))。Text; 我在代码上得到System.NullReferenceException。 这是webform2代码。

        {
            string name = Request.QueryString["Name"];

            if (name == "MAIN")
            {
                if (!IsPostBack)
                {
                    string fname = "Anonymous";
                    string lname = "Anonymous";
                    string email = "";
                    string mesg = "";

                    Page lastOne = (Page)Context.Handler;
                    string text = ((TextBox)lastOne.FindControl("MAIL")).Text;
                    LabelEMAIL.Text = text;
                    LabelMESG.Text = ((TextBox)lastOne.FindControl("MESAGE")).Text;
                    LabelFNAME.Text = fname;
                    LabelLNAME.Text = lname;
                }
                else
                {
                    Response.Redirect("WebForm1.aspx");
                }
            }
        } ```
*webfrom1 has the following code*
``` <table>
               <tr>
                   <td>Email: </td>
                   <td><asp:TextBox ID="MAIL" runat="server" OnTextChanged="TextBox1_TextChanged" ValidateRequestMode="Enabled" TextMode="Email" ></asp:TextBox></td>
                   <td><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" BackColor="White" ErrorMessage="*" ForeColor="Red" ControlToValidate="MAIL"></asp:RequiredFieldValidator></td>
               </tr>
               <tr>
                   <td>Message: </td>
                   <td><asp:TextBox ID="MESAGE" runat="server" Height="139px" OnTextChanged="TextBox2_TextChanged" Width="223px" Rows="10" TextMode="MultiLine"></asp:TextBox></td>
                   <td><asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*" Display="Dynamic" ForeColor="Red" ControlToValidate="MESAGE"></asp:RequiredFieldValidator></td>
               </tr>
           </table>

               <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" PostBackUrl="~/ResponseBack.aspx" Text="Submit" /> ```
评论