我就写了一个很简单的提交建议的东西。在textbox里写上字,点提交按钮就插入数据库。现在是点了提交后就刷新了,textbox和button都没有了。
没用ajax和xmlhttp,因为不知道怎么修改,觉得会改太多有些麻烦。 大家帮忙改一下,越简单越精炼越好。多谢多谢!页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="advice.aspx.cs" Inherits="advice" %><!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>
</head>
<body>
<form runat="server" id="form1">
<table>
<tr>
<td>
请提出您的宝贵意见和建议:
<input runat="server" id="adviceText" type="text"/>
<asp:Button runat="server" id="Submit" Text="提交" onclick="Submit_Click"/>
</td>
</tr>
</table>
</form>
</body>
</html>
后台代码://连接的字符串
public static readonly string ConnectionString = ConfigurationManager.AppSettings["oleconstring"];
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Submit_Click(object sender, EventArgs e)
{
string adText = adviceText.Value;
if (adText == "" || adText == null)
Response.Write("<script language=javascript>javascript:alert(\"请填写内容再提交!\");</script>");
else
{
OleDbConnection Conn = new OleDbConnection(ConnectionString);
OleDbCommand cmd = new OleDbCommand();
Conn.Open();
try
{
string Sql = "insert into advice(advice) values('" + adText + "')";
cmd.Connection = Conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = Sql;
int k = cmd.ExecuteNonQuery();
Conn.Close();
}
catch (OleDbException ex)
{
Conn.Close();
throw ex;
}
Response.Write("<script language=javascript>javascript:alert(\"提交成功!谢谢\");<script>");
adviceText.Value = "";
}
}
没用ajax和xmlhttp,因为不知道怎么修改,觉得会改太多有些麻烦。 大家帮忙改一下,越简单越精炼越好。多谢多谢!页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="advice.aspx.cs" Inherits="advice" %><!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>
</head>
<body>
<form runat="server" id="form1">
<table>
<tr>
<td>
请提出您的宝贵意见和建议:
<input runat="server" id="adviceText" type="text"/>
<asp:Button runat="server" id="Submit" Text="提交" onclick="Submit_Click"/>
</td>
</tr>
</table>
</form>
</body>
</html>
后台代码://连接的字符串
public static readonly string ConnectionString = ConfigurationManager.AppSettings["oleconstring"];
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Submit_Click(object sender, EventArgs e)
{
string adText = adviceText.Value;
if (adText == "" || adText == null)
Response.Write("<script language=javascript>javascript:alert(\"请填写内容再提交!\");</script>");
else
{
OleDbConnection Conn = new OleDbConnection(ConnectionString);
OleDbCommand cmd = new OleDbCommand();
Conn.Open();
try
{
string Sql = "insert into advice(advice) values('" + adText + "')";
cmd.Connection = Conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = Sql;
int k = cmd.ExecuteNonQuery();
Conn.Close();
}
catch (OleDbException ex)
{
Conn.Close();
throw ex;
}
Response.Write("<script language=javascript>javascript:alert(\"提交成功!谢谢\");<script>");
adviceText.Value = "";
}
}
解决方案 »
- mvc中创建view出错,懂的帮帮忙
- 请教:asp.net读取gbk编码的xml文件
- 高手帮忙下System.Windows.Browser.Net命名空间不存在
- 一个SHTML调用问题
- 求51job,中华英才等人才招聘网站职位高级搜索的实现方案
- 问个简单的问题,如何先触发按钮事件再刷新页面啊?
- 请问那里支持.net2.0 和SQL Server 2005的空间便宜点?
- mvc linq 动态查询 提示此上下文仅支持基元类型或枚举类型。
- 请教!!把pageID的值读到程序理http://localhost/display.aspx?pageID=1
- 求一sql语句
- 上传图片路径
- try catch 是否影响运行效率? 一会儿就结贴。在线。
晕坏了~
试试。
总觉得iframe不是很高级呢???