HtmlGeneric 控件不包含定义
HtmlGeneric Control does not contain a definition
我只想在 c# webforms 中使用 SQL 服务器创建一个插入表单 link。不幸的是,我遇到了这个错误并且不知道如何定义它们。
Error CS1061 'HtmlGenericControl' does not contain a definition for
'Text' and no accessible extension method 'Text' accepting a first
argument of type 'HtmlGenericControl' could be found (are you missing
a using directive or an assembly reference?)
请帮我正确定义'Text'。
这是我的 Contact.aspx:
<form id="form1" runat="server">
<div id="title">
<h1>REGISTER PAGE</h1>
</div>
<div id ="teble"></div>
<table class="auto-style1">
<tr>
<td>
<aspLabel ID="Label1" runat="server" Text="name"></aspLabel></td>
<td>
<aspTextBox ID="TextBox1" runat="server"></aspTextBox></td>
</tr>
<tr>
<td>
<aspLabel ID="Label2" runat="server" Text="email"></aspLabel></td>
<td>
<aspTextBox ID="TextBox2" runat="server"></aspTextBox></td>
</tr>
<tr>
<td>
<aspLabel ID="Label3" runat="server" Text="subject"></aspLabel></td>
<td>
<aspTextBox ID="TextBox3" runat="server"></aspTextBox></td>
</tr>
</table>
<div id="button">
<aspButton ID="Button1" runat="server" Text="submit" OnClick="Button1_Click" BackColor="Yellow" />
</div>
<div id="sim"></div>
<p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Table]"></asp:SqlDataSource>
</p>
这是我的 Contact.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.Data.SqlClient;
using System.Configuration;
public partial class Contact : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from Contact where name='" + TextBox1.Text + "'";
SqlCommand cmd = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());
if (temp == 1)
{
Response.Write("Student Already Exist");
}
conn.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into Table(Name,Email,Subject)values (@name,@email,@subject)";
SqlCommand cmd = new SqlCommand(insertQuery, conn);
cmd.Parameters.AddWithValue("@name", TextBox1.Text);
cmd.Parameters.AddWithValue("@email", TextBox2.Text);
cmd.Parameters.AddWithValue("@subject", TextBox3.Text);
cmd.ExecuteNonQuery();
Response.Write("Student registeration Successfully!!!thank you");
conn.Close();
}
catch (Exception ex)
{
Response.Write("error" + ex.ToString());
}
}
}
请检查您的 aspx 代码。
所有 asp 控件的格式不正确。
标签应该是
<asp:Label ID="Label2" runat="server" Text="email"></asp:Label>
而不是
<aspLabel ID="Label1" runat="server" Text="name"></aspLabel>
对于文本框和按钮等所有其他控件也是如此
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="submit" OnClick="Button1_Click" BackColor="Yellow" />
所有 asp 控件都应装饰成 <asp:Textbox>, <asp:Label>, <asp:Button>
等。
希望这会有所帮助。
我只想在 c# webforms 中使用 SQL 服务器创建一个插入表单 link。不幸的是,我遇到了这个错误并且不知道如何定义它们。
Error CS1061 'HtmlGenericControl' does not contain a definition for 'Text' and no accessible extension method 'Text' accepting a first argument of type 'HtmlGenericControl' could be found (are you missing a using directive or an assembly reference?)
请帮我正确定义'Text'。
这是我的 Contact.aspx:
<form id="form1" runat="server">
<div id="title">
<h1>REGISTER PAGE</h1>
</div>
<div id ="teble"></div>
<table class="auto-style1">
<tr>
<td>
<aspLabel ID="Label1" runat="server" Text="name"></aspLabel></td>
<td>
<aspTextBox ID="TextBox1" runat="server"></aspTextBox></td>
</tr>
<tr>
<td>
<aspLabel ID="Label2" runat="server" Text="email"></aspLabel></td>
<td>
<aspTextBox ID="TextBox2" runat="server"></aspTextBox></td>
</tr>
<tr>
<td>
<aspLabel ID="Label3" runat="server" Text="subject"></aspLabel></td>
<td>
<aspTextBox ID="TextBox3" runat="server"></aspTextBox></td>
</tr>
</table>
<div id="button">
<aspButton ID="Button1" runat="server" Text="submit" OnClick="Button1_Click" BackColor="Yellow" />
</div>
<div id="sim"></div>
<p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Table]"></asp:SqlDataSource>
</p>
这是我的 Contact.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.Data.SqlClient;
using System.Configuration;
public partial class Contact : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from Contact where name='" + TextBox1.Text + "'";
SqlCommand cmd = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());
if (temp == 1)
{
Response.Write("Student Already Exist");
}
conn.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into Table(Name,Email,Subject)values (@name,@email,@subject)";
SqlCommand cmd = new SqlCommand(insertQuery, conn);
cmd.Parameters.AddWithValue("@name", TextBox1.Text);
cmd.Parameters.AddWithValue("@email", TextBox2.Text);
cmd.Parameters.AddWithValue("@subject", TextBox3.Text);
cmd.ExecuteNonQuery();
Response.Write("Student registeration Successfully!!!thank you");
conn.Close();
}
catch (Exception ex)
{
Response.Write("error" + ex.ToString());
}
}
}
请检查您的 aspx 代码。
所有 asp 控件的格式不正确。
标签应该是
<asp:Label ID="Label2" runat="server" Text="email"></asp:Label>
而不是
<aspLabel ID="Label1" runat="server" Text="name"></aspLabel>
对于文本框和按钮等所有其他控件也是如此
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="submit" OnClick="Button1_Click" BackColor="Yellow" />
所有 asp 控件都应装饰成 <asp:Textbox>, <asp:Label>, <asp:Button>
等。
希望这会有所帮助。