弹出确定后
在写一个语句
Response.Register(页面);
最基本的取巧、方法

解决方案 »

  1.   

    在page_load里面寫if(!page.ispostback)
    {
    }
    ???是這樣嗎
    我是新手,能否用代碼明示
      

  2.   

    我的代碼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();    }
    }
      

  3.   

    提交后刷新默认又提交了一次!
    提交后最后重新加载页面:response.redirect
      

  4.   

    能否用其他方式.
    請用代碼明示
    Response.Redirect("index.aspx?");效果不是很好
      

  5.   

    ClientScript.RegisterStartupScript
    改成
    clientscript.RegisterClientScriptBlock
    试一下
      

  6.   

    this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('庫位不符合!'); window.location.href = window.location.href;", true);