<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function Button1_onclick() {
if (document.getElementById("Text1").value == "")
{
alert("请填写用户名! ");
return false;
}
if (document.getElementById("Text2").value == "") {
alert("请填写密码! ");
return false;
}
}
// ]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Text1" type="text"/>
<input id="Text2" type="text"/>
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" runat="server" /></div>
</form>
</body>
</html>
不用这种控件<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 用input开头的控件
把文本框的值添加到sql数据库中
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new UserBLL().getLogin(TextBox1.Text,TextBox2.Text);
if (ds.Tables[0].Rows.Count > 0)
Response.Write("<script type=\"text/javascript\">top.location.href='Default2.aspx';</script>");
else
Response.Write("<script type=\"text/javascript\">alert('登陆失败');</script>");
}
怎么用html控件把文本框的数据,添加到数据库中
12 个解决方案
#1
#2
<input id="Text1" type="text" runat="server"/>
<input id="Text2" type="text" runat="server"/>
不过这种跟服务器控件没什么区别。。
哈哈
<input id="Text2" type="text" runat="server"/>
不过这种跟服务器控件没什么区别。。
哈哈
#3
Request["Input控件ID"] 取值。
#4
这样也行
<input type="text" name="Text1" />
string str =Request.Form["Text1"].ToString();
<input type="text" name="Text1" />
string str =Request.Form["Text1"].ToString();
#5
<input id="Text1" type="text" runat="server"/>
<input id="Text2" type="text" runat="server" />
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" onserverclick="Button1_Click" runat="server" />
using System.Data.SqlClient;
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText="insert into 表 (列1,列2) values(@value1,@value2)";
cmd.Parameters.AddWithValue("@value1", Text1.value);
cmd.Parameters.AddWithValue("@value2", Text2.value)
using (SqlConnection conn = new SqlConnection("server=.;database=yourdb;uid=sa;pwd=123"))
{
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
}
}
<input id="Text2" type="text" runat="server" />
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" onserverclick="Button1_Click" runat="server" />
using System.Data.SqlClient;
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText="insert into 表 (列1,列2) values(@value1,@value2)";
cmd.Parameters.AddWithValue("@value1", Text1.value);
cmd.Parameters.AddWithValue("@value2", Text2.value)
using (SqlConnection conn = new SqlConnection("server=.;database=yourdb;uid=sa;pwd=123"))
{
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
}
}
#6
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" runat="server" onserverclick="Button1_Click" /></div>
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new UserBLL().getLogin(Text1.Value,Text2.Value);
if (ds.Tables[0].Rows.Count > 0)
Response.Write("<script type=\"text/javascript\">top.location.href='Default2.aspx';</script>");
else
Response.Write("<script type=\"text/javascript\">alert('账号密码输入有误!');</script>");
}
我这样改怎么不触发事件啊!
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new UserBLL().getLogin(Text1.Value,Text2.Value);
if (ds.Tables[0].Rows.Count > 0)
Response.Write("<script type=\"text/javascript\">top.location.href='Default2.aspx';</script>");
else
Response.Write("<script type=\"text/javascript\">alert('账号密码输入有误!');</script>");
}
我这样改怎么不触发事件啊!
#7
DataSet ds = new UserBLL().getLogin(Text1.Value,Text2.Value);在这句左边打个断点。
#8
这个调试 我很清楚,还是没进入事件
#9
type="button"改为 type="submit"
#10
谢谢大家这问题解决了
#11
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function CheckForm() {
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="txtName" runat="server" />
<input type="password" id="txtPassword" runat="server" />
<input type="Submit" id="btnSubmit" runat="server" onclick="return CheckForm();" onserverclick="btnSubmit_Click" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
Response.Write(txtName.Value);
}
}
#12
onserverclick="Button1_Click"
他的功能和双击<asp:控件的效果一样,可以再后台处理sql语句
或者用ajax response,request把信息传到.ashx界面处理后返回信息
他的功能和双击<asp:控件的效果一样,可以再后台处理sql语句
或者用ajax response,request把信息传到.ashx界面处理后返回信息
#1
#2
<input id="Text1" type="text" runat="server"/>
<input id="Text2" type="text" runat="server"/>
不过这种跟服务器控件没什么区别。。
哈哈
<input id="Text2" type="text" runat="server"/>
不过这种跟服务器控件没什么区别。。
哈哈
#3
Request["Input控件ID"] 取值。
#4
这样也行
<input type="text" name="Text1" />
string str =Request.Form["Text1"].ToString();
<input type="text" name="Text1" />
string str =Request.Form["Text1"].ToString();
#5
<input id="Text1" type="text" runat="server"/>
<input id="Text2" type="text" runat="server" />
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" onserverclick="Button1_Click" runat="server" />
using System.Data.SqlClient;
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText="insert into 表 (列1,列2) values(@value1,@value2)";
cmd.Parameters.AddWithValue("@value1", Text1.value);
cmd.Parameters.AddWithValue("@value2", Text2.value)
using (SqlConnection conn = new SqlConnection("server=.;database=yourdb;uid=sa;pwd=123"))
{
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
}
}
<input id="Text2" type="text" runat="server" />
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" onserverclick="Button1_Click" runat="server" />
using System.Data.SqlClient;
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText="insert into 表 (列1,列2) values(@value1,@value2)";
cmd.Parameters.AddWithValue("@value1", Text1.value);
cmd.Parameters.AddWithValue("@value2", Text2.value)
using (SqlConnection conn = new SqlConnection("server=.;database=yourdb;uid=sa;pwd=123"))
{
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
}
}
#6
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" runat="server" onserverclick="Button1_Click" /></div>
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new UserBLL().getLogin(Text1.Value,Text2.Value);
if (ds.Tables[0].Rows.Count > 0)
Response.Write("<script type=\"text/javascript\">top.location.href='Default2.aspx';</script>");
else
Response.Write("<script type=\"text/javascript\">alert('账号密码输入有误!');</script>");
}
我这样改怎么不触发事件啊!
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new UserBLL().getLogin(Text1.Value,Text2.Value);
if (ds.Tables[0].Rows.Count > 0)
Response.Write("<script type=\"text/javascript\">top.location.href='Default2.aspx';</script>");
else
Response.Write("<script type=\"text/javascript\">alert('账号密码输入有误!');</script>");
}
我这样改怎么不触发事件啊!
#7
DataSet ds = new UserBLL().getLogin(Text1.Value,Text2.Value);在这句左边打个断点。
#8
这个调试 我很清楚,还是没进入事件
#9
type="button"改为 type="submit"
#10
谢谢大家这问题解决了
#11
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function CheckForm() {
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="txtName" runat="server" />
<input type="password" id="txtPassword" runat="server" />
<input type="Submit" id="btnSubmit" runat="server" onclick="return CheckForm();" onserverclick="btnSubmit_Click" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
Response.Write(txtName.Value);
}
}
#12
onserverclick="Button1_Click"
他的功能和双击<asp:控件的效果一样,可以再后台处理sql语句
或者用ajax response,request把信息传到.ashx界面处理后返回信息
他的功能和双击<asp:控件的效果一样,可以再后台处理sql语句
或者用ajax response,request把信息传到.ashx界面处理后返回信息