[英]Control 'ContentPlaceHolder1_Button1' of type 'Button' must be placed inside a form tag with runat=server
I am new to asp.net.我是asp.net的新手。 I having problem to resolve this error 'Button' must be placed inside a form tag with runat=server.我在解决此错误时遇到问题必须将“按钮”放置在带有 runat=server 的表单标记中。 Even runat server placed within the form tag or anything did I missed or I wrongly used any code甚至放在表单标签中的 runat 服务器或我错过的任何东西,或者我错误地使用了任何代码
My c# .net code(login.aspx):我的 c# .net 代码(login.aspx):
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
#Reset1
{
width: 75px;
margin-top: 0px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<form id="form1" runat="server">
<p>
<br />
</p>
<div style="border:5px solid blue;
border-color:Navy;
background-color:#f4d7f7;
width:645px;
height:426px;
margin-left:330px">
<br />
\<br />
<br />
<asp:Label ID="Label1" runat="server"
style="height: 24px"
Text="Email Based Student Intimation System" Font-Bold="True"
Font-Italic="True" Font-Size="X-Large" ForeColor="#000099" Height="26px"
Width="411px"></asp:Label>
<br />
<br />
<br />
<p style="height: 43px">
<asp:Label ID="Label4" runat="server" Font-Bold="True" Font-Italic="False"
Font-Overline="False" ForeColor="black" Font-Size="Large"
style="height: 23px; width: 109px"
Text="USER NAME"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"
style="width: 171px; height: 27px; "
TabIndex="3" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
</p>
<p style="height: 56px">
<asp:Label ID="Label3" runat="server"
style="width: 103px; height: 23px; margin-top: 0px;"
Text="PASSWORD" ForeColor="black" Font-Bold="True" Font-Italic="False" Font-Size="Large"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"
style="height: 27px; width: 171px"
TabIndex="4" TextMode="Password"></asp:TextBox>
</p>
<p style="height: 51px">
<asp:Button
ID="Button1" OnClick="Button1_Click1" runat="server" Text="Login" />
<input id="Reset1" type="reset" value="reset" /> </p>
<p style="height: 57px">
<asp:Button
ID="Btnew" runat="server" PostBackUrl="~/New registration.aspx"
Text="NEW REGISTRATION" Height="33px" Width="201px" />
</p>
<p style="height: 57px">
</p>
</div>
</form>
</asp:Content>
and my login.aspx.cs code as below:和我的 login.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;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\SOWNDHARYA E\Documents\sow.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand cmd = new SqlCommand();
DataSet ds=new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
}
//protected void Bnlog_Click(object sender, EventArgs e)
protected void Button1_Click1(object sender, EventArgs e)
{
//if (RadioButton1.Checked == true)
//{
cmd.Connection = con;
cmd.CommandText = "select * from STAFF where ID='" + TextBox1.Text + "' and DOB='" + TextBox2.Text + "'";
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("module.aspx");
}
If any mistake my kind apologies, please help me to resolve.如果有任何错误,我深表歉意,请帮助我解决。 I am using microsoft visual studio 2010 and sql server我正在使用 Microsoft Visual Studio 2010 和 sql server
I am new to asp.net.我是asp.net的新手。 I having problem to resolve this error 'Button' must be placed inside a form tag with runat=server.我在解决此错误时遇到问题必须将“按钮”放置在带有 runat=server 的表单标记中。 Even runat server placed within the form tag or anything did I missed or I wrongly used any code甚至放在表单标签中的 runat 服务器或我错过的任何东西,或者我错误地使用了任何代码
My c# .net code(login.aspx):我的 c# .net 代码(login.aspx):
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
#Reset1
{
width: 75px;
margin-top: 0px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<form id="form1" runat="server">
<p>
<br />
</p>
<div style="border:5px solid blue;
border-color:Navy;
background-color:#f4d7f7;
width:645px;
height:426px;
margin-left:330px">
<br />
\<br />
<br />
<asp:Label ID="Label1" runat="server"
style="height: 24px"
Text="Email Based Student Intimation System" Font-Bold="True"
Font-Italic="True" Font-Size="X-Large" ForeColor="#000099" Height="26px"
Width="411px"></asp:Label>
<br />
<br />
<br />
<p style="height: 43px">
<asp:Label ID="Label4" runat="server" Font-Bold="True" Font-Italic="False"
Font-Overline="False" ForeColor="black" Font-Size="Large"
style="height: 23px; width: 109px"
Text="USER NAME"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"
style="width: 171px; height: 27px; "
TabIndex="3" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
</p>
<p style="height: 56px">
<asp:Label ID="Label3" runat="server"
style="width: 103px; height: 23px; margin-top: 0px;"
Text="PASSWORD" ForeColor="black" Font-Bold="True" Font-Italic="False" Font-Size="Large"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"
style="height: 27px; width: 171px"
TabIndex="4" TextMode="Password"></asp:TextBox>
</p>
<p style="height: 51px">
<asp:Button
ID="Button1" OnClick="Button1_Click1" runat="server" Text="Login" />
<input id="Reset1" type="reset" value="reset" /> </p>
<p style="height: 57px">
<asp:Button
ID="Btnew" runat="server" PostBackUrl="~/New registration.aspx"
Text="NEW REGISTRATION" Height="33px" Width="201px" />
</p>
<p style="height: 57px">
</p>
</div>
</form>
</asp:Content>
and my login.aspx.cs code as below:和我的 login.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;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\SOWNDHARYA E\Documents\sow.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand cmd = new SqlCommand();
DataSet ds=new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
}
//protected void Bnlog_Click(object sender, EventArgs e)
protected void Button1_Click1(object sender, EventArgs e)
{
//if (RadioButton1.Checked == true)
//{
cmd.Connection = con;
cmd.CommandText = "select * from STAFF where ID='" + TextBox1.Text + "' and DOB='" + TextBox2.Text + "'";
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("module.aspx");
}
If any mistake my kind apologies, please help me to resolve.如果有任何错误,我深表歉意,请帮助我解决。 I am using microsoft visual studio 2010 and sql server我正在使用 Microsoft Visual Studio 2010 和 sql server
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.