<form action="" method="post">
<table width="470" border="0" align="center" cellpadding="0" cellspacing="0" class="tableGroupbuy">
<tr>
<th scope="row">名称:</th>
<td><input type="text" name="name" class="txt" /><i>*</i></td>
</tr>
<tr>
<th scope="row">地址:</th>
<td><input type="text" name="accress" class="txt long" /><i>*</i></td>
</tr>
<tr>
<th scope="row"> </th>
<td><input type="submit" name="" value="确认" class="btn"/>
<input type="reset" name="" value="重置" class="btn"/>
</td>
</tr>
</table>
</form> </div>input不能想<asp:button>那样在CS里写,请问input要如何实现往数据库添加内容,就像是这样就可以
protected void submit_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=.;database=abc;uid=sa;pwd=aa");
string InsertSql = "insert into tm_groupbuy (unitname,address) values (" + Name.Text + "," + Accress.Text + ")";
conn.Open();
SqlCommand InsertCmd = new SqlCommand(InsertSql, conn);
InsertCmd.CommandType = CommandType.Text;
InsertCmd.ExecuteNonQuery();
if (InsertCmd.ExecuteNonQuery() == 1)
{
Response.Write("插入成功");
}
else
{
Response.Write("没有数据插入");
}
conn.Close();
}
<table width="470" border="0" align="center" cellpadding="0" cellspacing="0" class="tableGroupbuy">
<tr>
<th scope="row">名称:</th>
<td><input type="text" name="name" class="txt" /><i>*</i></td>
</tr>
<tr>
<th scope="row">地址:</th>
<td><input type="text" name="accress" class="txt long" /><i>*</i></td>
</tr>
<tr>
<th scope="row"> </th>
<td><input type="submit" name="" value="确认" class="btn"/>
<input type="reset" name="" value="重置" class="btn"/>
</td>
</tr>
</table>
</form> </div>input不能想<asp:button>那样在CS里写,请问input要如何实现往数据库添加内容,就像是这样就可以
protected void submit_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=.;database=abc;uid=sa;pwd=aa");
string InsertSql = "insert into tm_groupbuy (unitname,address) values (" + Name.Text + "," + Accress.Text + ")";
conn.Open();
SqlCommand InsertCmd = new SqlCommand(InsertSql, conn);
InsertCmd.CommandType = CommandType.Text;
InsertCmd.ExecuteNonQuery();
if (InsertCmd.ExecuteNonQuery() == 1)
{
Response.Write("插入成功");
}
else
{
Response.Write("没有数据插入");
}
conn.Close();
}
Request.Form["accress"]
input type="submit" name="" value="确认" class="btn"/>
或AJAX取值document赋值
或添加runat="server" Htmlinput
input的提交要如何在CS页获取提交按钮呢?
<input runat="server" type="text" id="name" />在input里加一个属性,runat="server",这样你就可以在后台获得name的对象了,接收值的时候,用name.Value就可以在后台获得文本框的值了
{
SqlConnection conn = new SqlConnection("server=.;database=TM_Shop1;uid=sa;pwd=123");
string InsertSql = "insert into tm_groupbuy (unitname,address) values (" + Request.Form["UnitName"] + "," + Request.Form["Accress"] + ")";
conn.Open();
SqlCommand InsertCmd = new SqlCommand(InsertSql, conn);
InsertCmd.CommandType = CommandType.Text;
InsertCmd.ExecuteNonQuery();
if (InsertCmd.ExecuteNonQuery() == 1)
{
Response.Write("插入成功");
}
else
{
Response.Write("没有数据插入");
}
conn.Close();
}这样写获取不到怎么办呢?
<th scope="row">名称:</th>
<td><input type="text" name="UnitName" class="txt" runat="server" /><i>*</i></td>
</tr>
<tr>
<th scope="row">地址:</th>
<td><input type="text" name="Accress" class="txt long" runat="server"/><i>*</i></td>
</tr>
<input type="text" name="Accress1" class="txt long" runat="server"/>如果希望隐藏此控件.就加
<input type="hidden" name="Accress1" class="txt long" runat="server"/>
<input id="Hidden1" type="hidden" name="Accress1" class="txt long" runat="server"/>protected void submit_Click(object sender, EventArgs e)
{}
这样还是不好用,我已经在网上搜了很多种方法了,可是还是不好用,好急啊
<input type="text" name="name" class="txt" />
<input id="submit" type="submit" name="" value="确认" runat="server" class="btn" />后台:
string name=Request.Params["name"];
string s= Request.Params["txt"];
string ss = Request.Form["txt"];
这两个都 可以,,
Request.Form["name"]获取html控件的值
<input name="username" type="text" />
<input name="password" type="password" />
<input name="submit" type="submit" value="登录" />
</form>a.aspx.cs
void Page_load(){
if(Request.Form["submit"]!=null){
string username=Request.Form["username"];
string password=Request.Form["password"];
//sign in
}
}
1)页面查询控件取值:Request.Form["name"]
Request.Form["accress"]2)给input控件加上服务器标识
ruant="server"