刷新页面时出现上次执行后的提示框 弹出确定后在写一个语句Response.Register(页面);最基本的取巧、方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在page_load里面寫if(!page.ispostback){}???是這樣嗎我是新手,能否用代碼明示 我的代碼public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void txtEmployee_TextChanged(object sender, EventArgs e) { txtEmployee.Text = txtEmployee.Text.Trim().ToString().ToUpper(); SqlConnection sqlconn = new SqlConnection(ConfigurationManager.ConnectionStrings["ICAS_METConnectionString"].ToString()); string strsql = "select name from cupa01h where employee='" + txtEmployee.Text.ToString().ToUpper() + "'"; sqlconn.Open(); SqlDataAdapter da = new SqlDataAdapter(strsql, sqlconn); DataSet data = new DataSet(); da.Fill(data, "emp"); if (data.Tables["emp"].Rows.Count == 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('員工工號不存在!')", true); txtEmployee.Text = ""; txtEmpName.Text = ""; txtStockName.Text = ""; txtEmployee.Focus(); } else { txtEmpName.Text = data.Tables["emp"].Rows[0][0].ToString(); } sqlconn.Close(); } protected void btnSend_Click(object sender, EventArgs e) { if (txtStock.Text.Trim().Length.Equals(0)) { cvCheck.IsValid = false; cvCheck.ErrorMessage = "不能為空"; return; } if (txtEmployee.Text.Trim().Length.Equals(0)) { ceCheck.IsValid = false; ceCheck.ErrorMessage = "不能為空"; return; } else { SqlConnection sqlslt = new SqlConnection(ConfigurationManager.ConnectionStrings["ICAS_METConnectionString"].ToString()); sqlslt.Open(); string strslt = "select * from icamttr_area_authority01 where mt_area+auth_type+emp_no='" + txtStock.Text.ToString() + "'+'" + ddlType.SelectedValue.ToString() + "'+'" + txtEmployee.Text + "'"; SqlDataAdapter da = new SqlDataAdapter(strslt, sqlslt); DataSet data = new DataSet(); da.Fill(data, "empt"); if (data.Tables["empt"].Rows.Count>0) { this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('該員工已有該庫存權限!')", true); sqlslt.Close(); txtStock.Text = ""; txtEmployee.Text = ""; txtEmpName.Text = ""; txtStockName.Text = ""; txtStock.Focus(); } if (data.Tables["empt"].Rows.Count == 0) { SqlConnection sqlinsert = new SqlConnection(ConfigurationManager.ConnectionStrings["ICAS_METConnectionString"].ToString()); sqlinsert.Open(); String strSql = @"insert into icamttr_area_authority01 ( mt_area, auth_type, emp_no, emp_name, insert_datetime, insert_user) values ('" + txtStock.Text.ToString() + "','" + ddlType.SelectedValue.ToString() + "','" + txtEmployee.Text + "','" + txtEmpName.Text + "','" + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") + "','" + Request.LogonUserIdentity.Name.ToUpper().Replace("ICHIA\\","") + "')"; SqlCommand Insert_Cmd_Project = new SqlCommand(strSql, sqlinsert); Insert_Cmd_Project.ExecuteNonQuery(); sqlinsert.Close(); this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('庫存權限新增完成!')", true); txtStock.Text = ""; txtEmployee.Text = ""; txtEmpName.Text = ""; txtStockName.Text = ""; txtStock.Focus(); GridView1.DataBind(); GridView1.Visible = true; } } } protected void imagebbtSelect_Click(object sender, ImageClickEventArgs e) { Response.Redirect("gridview.aspx?"); } protected void imagebbtCancel_Click(object sender, ImageClickEventArgs e) { ScriptManager.RegisterStartupScript(this, this.GetType(), "Query", "window.close();", true); } protected void txtStock_TextChanged(object sender, EventArgs e) { txtStock.Text = txtStock.Text.Trim().ToString().ToUpper(); SqlConnection sqlconn = new SqlConnection(ConfigurationManager.ConnectionStrings["ICAS_METConnectionString"].ToString()); string strselect = "select mt_area,mt_name from iepb07h where mt_area='" + txtStock.Text.ToString().ToUpper() + "'"; sqlconn.Open(); SqlDataAdapter da = new SqlDataAdapter(strselect, sqlconn); DataSet data = new DataSet(); da.Fill(data, "emp"); if (data.Tables["emp"].Rows.Count == 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('庫位不符合!')", true); txtStock.Text = ""; txtEmployee.Text = ""; txtEmpName.Text = ""; txtStockName.Text = ""; txtStock.Focus(); } else { txtStockName.Text = data.Tables["emp"].Rows[0][1].ToString(); } sqlconn.Close(); }} 提交后刷新默认又提交了一次!提交后最后重新加载页面:response.redirect 能否用其他方式.請用代碼明示Response.Redirect("index.aspx?");效果不是很好 ClientScript.RegisterStartupScript改成clientscript.RegisterClientScriptBlock试一下 this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('庫位不符合!'); window.location.href = window.location.href;", true); DataTable进行汇总 我想在交警网自动输入车牌号和机动车识别码查询违章信息,。net高手们帮我看看!!! 脚本错误 .NET可以使用JS产生的Cookie吗? 介绍书籍 Md5加密算法及调用VB的inputbox 看c#高级编程第3版的一点疑问 哪位大神给一个C#Winfroms上传图片的代码 谁知道这个控件的名称和事件.方法,立即给分 如何在两个父子表中插入数据? TcpListener和TcpClient的问题 可不可以通过script调用系统视频驱动?跪求各位大侠
{
}
???是這樣嗎
我是新手,能否用代碼明示
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void txtEmployee_TextChanged(object sender, EventArgs e)
{
txtEmployee.Text = txtEmployee.Text.Trim().ToString().ToUpper();
SqlConnection sqlconn = new SqlConnection(ConfigurationManager.ConnectionStrings["ICAS_METConnectionString"].ToString());
string strsql = "select name from cupa01h where employee='" + txtEmployee.Text.ToString().ToUpper() + "'";
sqlconn.Open();
SqlDataAdapter da = new SqlDataAdapter(strsql, sqlconn);
DataSet data = new DataSet();
da.Fill(data, "emp");
if (data.Tables["emp"].Rows.Count == 0)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('員工工號不存在!')", true);
txtEmployee.Text = "";
txtEmpName.Text = "";
txtStockName.Text = "";
txtEmployee.Focus();
}
else
{ txtEmpName.Text = data.Tables["emp"].Rows[0][0].ToString();
}
sqlconn.Close();
}
protected void btnSend_Click(object sender, EventArgs e)
{
if (txtStock.Text.Trim().Length.Equals(0))
{
cvCheck.IsValid = false;
cvCheck.ErrorMessage = "不能為空";
return;
}
if (txtEmployee.Text.Trim().Length.Equals(0))
{
ceCheck.IsValid = false;
ceCheck.ErrorMessage = "不能為空";
return;
}
else
{ SqlConnection sqlslt = new SqlConnection(ConfigurationManager.ConnectionStrings["ICAS_METConnectionString"].ToString());
sqlslt.Open();
string strslt = "select * from icamttr_area_authority01 where mt_area+auth_type+emp_no='" + txtStock.Text.ToString() + "'+'" + ddlType.SelectedValue.ToString() + "'+'" + txtEmployee.Text + "'";
SqlDataAdapter da = new SqlDataAdapter(strslt, sqlslt);
DataSet data = new DataSet();
da.Fill(data, "empt");
if (data.Tables["empt"].Rows.Count>0)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('該員工已有該庫存權限!')", true);
sqlslt.Close();
txtStock.Text = "";
txtEmployee.Text = "";
txtEmpName.Text = "";
txtStockName.Text = "";
txtStock.Focus(); }
if (data.Tables["empt"].Rows.Count == 0)
{
SqlConnection sqlinsert = new SqlConnection(ConfigurationManager.ConnectionStrings["ICAS_METConnectionString"].ToString());
sqlinsert.Open();
String strSql = @"insert into
icamttr_area_authority01
(
mt_area,
auth_type,
emp_no,
emp_name,
insert_datetime,
insert_user)
values
('"
+ txtStock.Text.ToString() + "','"
+ ddlType.SelectedValue.ToString() + "','"
+ txtEmployee.Text + "','"
+ txtEmpName.Text + "','"
+ DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") + "','" + Request.LogonUserIdentity.Name.ToUpper().Replace("ICHIA\\","") + "')"; SqlCommand Insert_Cmd_Project = new SqlCommand(strSql, sqlinsert);
Insert_Cmd_Project.ExecuteNonQuery();
sqlinsert.Close();
this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('庫存權限新增完成!')", true);
txtStock.Text = "";
txtEmployee.Text = "";
txtEmpName.Text = "";
txtStockName.Text = "";
txtStock.Focus();
GridView1.DataBind();
GridView1.Visible = true;
}
}
} protected void imagebbtSelect_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("gridview.aspx?");
}
protected void imagebbtCancel_Click(object sender, ImageClickEventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Query", "window.close();", true);
}
protected void txtStock_TextChanged(object sender, EventArgs e)
{
txtStock.Text = txtStock.Text.Trim().ToString().ToUpper();
SqlConnection sqlconn = new SqlConnection(ConfigurationManager.ConnectionStrings["ICAS_METConnectionString"].ToString());
string strselect = "select mt_area,mt_name from iepb07h where mt_area='" + txtStock.Text.ToString().ToUpper() + "'";
sqlconn.Open();
SqlDataAdapter da = new SqlDataAdapter(strselect, sqlconn);
DataSet data = new DataSet();
da.Fill(data, "emp");
if (data.Tables["emp"].Rows.Count == 0)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('庫位不符合!')", true);
txtStock.Text = "";
txtEmployee.Text = "";
txtEmpName.Text = "";
txtStockName.Text = "";
txtStock.Focus();
}
else
{ txtStockName.Text = data.Tables["emp"].Rows[0][1].ToString();
} sqlconn.Close(); }
}
提交后最后重新加载页面:response.redirect
請用代碼明示
Response.Redirect("index.aspx?");效果不是很好
改成
clientscript.RegisterClientScriptBlock
试一下