我有个问题。我在 c# 中创建了 asp.net 网页。我使用 Visuals Studio 为您提供的默认母版页创建了它。在 register.aspx 中有一个用于用户名的文本框,例如 tihs:
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
<asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
CssClass="failureNotification" ErrorMessage="User Name is required." ToolTip="User Name is required."
ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>
在cs文件夹中,在按钮下我放了一个将注册用户放入数据库的代码,但它找不到文本框的变量。这里有什么问题?
protected void RegisterUser_CreatedUser(object sender, EventArgs e)
{
//FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false
//string continueUrl = RegisterUser.ContinueDestinationPageUrl;
//if (String.IsNullOrEmpty(continueUrl))
//{
// continueUrl = "~/";
//}
//Response.Redirect(continueUrl);
try
{
SqlConnection objcon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
DataTable objdatatable = new DataTable();
string validationquery = "select * from Uporabniki where username=`" + UserName.Text + "`";
SqlDataAdapter objdavalidate = new SqlDataAdapter(validationquery, objcon);
objdavalidate.SelectCommand.CommandType = CommandType.Text;
objdavalidate.Fill(objdatatable);
if (objdatatable.Rows.Count > 0)
{
...