当我填写表单时,我有一个带有表单的页面,我想在我的 c# 代码隐藏文件中访问该表单数据。
注册.aspx:
<%@ Page Title="Home" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="True" CodeBehind="Register.aspx.cs" Inherits="Informito._Default" %>
<div>
<table class="style1">
<tr>
<td>Utilizador:</td>
<td><asp:TextBox ID="Utilizador" name="Utilizador" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Password:</td>
<td><asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox></td>
</tr>
</table>
</div>
<asp:Button ID="Button1" runat="server" Text="Registar" OnClick="Registar"/>
注册.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.SqlClient;
using Informito.Admins;
namespace Informito
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void Registar(object sender, EventArgs e)
{
string Username = Utilizador.Text; //Error here: Object reference not set to an instance of an object.
string Password= Password.Text;
RegisterUser(Username, Password, 1);
}
}
}
Register.aspx.designer.cs:
namespace Informito {
public partial class _Default {
protected global::System.Web.UI.WebControls.LoginView LoginView1;
protected global::System.Web.UI.WebControls.TextBox Utilizador;
protected global::System.Web.UI.WebControls.TextBox Password;
}
}
我必须使用什么函数从 asp.net 文本框中读取并通过 c# 代码隐藏变量将其传递给?