asp.net中怎么让页面刷新之后代码不重新运行,只是页面重新加载一下
usingSystem;usingSystem.Collections;usingSystem.Configuration;usingSystem.Data;usingS...
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class MessageBoard : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
if (TextBox1.Text == "" || TextBox2.Text == "")
{
Page.RegisterStartupScript("", "<script>alert('请输入留言主题和内容!');</script>");
}
else {
try {
string connstr=ConfigurationManager.ConnectionStrings["MessageConnectionString"].ConnectionString;
SqlConnection conn=new SqlConnection (connstr);
conn.Open();
SqlCommand cmd = new SqlCommand("dbo.proc_insertmessageinfo", conn);
cmd.CommandType=CommandType.StoredProcedure;
SqlParameter para2 = new SqlParameter("@heading", SqlDbType.NVarChar);
para2.Value = TextBox1.Text;
cmd.Parameters.Add(para2);
SqlParameter para3 = new SqlParameter("@content", SqlDbType.NVarChar);
para3.Value = TextBox2.Text;
cmd.Parameters.Add(para3);
SqlParameter para4 = new SqlParameter("@time", SqlDbType.DateTime);
para4.Value = DateTime.Now.ToShortDateString();
cmd.Parameters.Add(para4);
cmd.ExecuteNonQuery();
Page.RegisterStartupScript("","<script>alert('发表成功!');</script>");
conn.Close();
}
catch{
}
}
}
} 展开
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class MessageBoard : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
if (TextBox1.Text == "" || TextBox2.Text == "")
{
Page.RegisterStartupScript("", "<script>alert('请输入留言主题和内容!');</script>");
}
else {
try {
string connstr=ConfigurationManager.ConnectionStrings["MessageConnectionString"].ConnectionString;
SqlConnection conn=new SqlConnection (connstr);
conn.Open();
SqlCommand cmd = new SqlCommand("dbo.proc_insertmessageinfo", conn);
cmd.CommandType=CommandType.StoredProcedure;
SqlParameter para2 = new SqlParameter("@heading", SqlDbType.NVarChar);
para2.Value = TextBox1.Text;
cmd.Parameters.Add(para2);
SqlParameter para3 = new SqlParameter("@content", SqlDbType.NVarChar);
para3.Value = TextBox2.Text;
cmd.Parameters.Add(para3);
SqlParameter para4 = new SqlParameter("@time", SqlDbType.DateTime);
para4.Value = DateTime.Now.ToShortDateString();
cmd.Parameters.Add(para4);
cmd.ExecuteNonQuery();
Page.RegisterStartupScript("","<script>alert('发表成功!');</script>");
conn.Close();
}
catch{
}
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询