我有问题。我在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)
{
...