问题描述
我在我的数据库中插入一行。在页面刷新后插入后,即使我没有点击该按钮,我的点击事件也会自动触发。任何人都可以提出建议。任何帮助都将受到赞赏。
I am inserting a row in my database.After inserting when the page is refreshed my click event automatically triggers even though i have not clicked that button.Can anyone suggest something.Any help would be appreciated.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// pnlBegin.Visible = false;
pnlContactPhoneEmail.Visible = false;
pnlCopy.Visible = false;
pnlCustomer.Visible = false;
// pnlNewOrderInfo.Visible = false;
pnlOrderBlank.Visible = false;
//pnlOrderCurrent.Visible = false;
pnlOrderHeaderInfo.Visible = false;
//pnlOrderLineInfo.Visible = false;
pnlReload.Visible = false;
pnlShiptoAddress.Visible = false;
}
else
{
}
}
protected void btnNew_Click(object sender, EventArgs e)
{
connfordata.Open();
SqlCommand cmdfrexesp = new SqlCommand("sp_SRXO_InsDocTemplate", connfordata);
cmdfrexesp.Parameters.AddWithValue("@W113_CompanyID", 5);
cmdfrexesp.Parameters.AddWithValue("@W113_WebstoreID", 23);
cmdfrexesp.Parameters.Add("@W113_XMLID", SqlDbType.Int).Direction = ParameterDirection.Output;
cmdfrexesp.CommandType = CommandType.StoredProcedure;
cmdfrexesp.ExecuteNonQuery();
int yourResult = Convert.ToInt32(cmdfrexesp.Parameters["@W113_XMLID"].Value);
connfordata.Close();
txtCurrentOrder.Text = yourResult.ToString();
}
}
插入一行后,新按钮会自动触发。
}
The new button gets automatically triggered after i insert a row.
推荐答案
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// pnlBegin.Visible = false;
pnlContactPhoneEmail.Visible = false;
pnlCopy.Visible = false;
pnlCustomer.Visible = false;
// pnlNewOrderInfo.Visible = false;
pnlOrderBlank.Visible = false;
//pnlOrderCurrent.Visible = false;
pnlOrderHeaderInfo.Visible = false;
//pnlOrderLineInfo.Visible = false;
pnlReload.Visible = false;
pnlShiptoAddress.Visible = false;
}
else
{
btnNew_Click(btnNew, null);//btnNew is Button Id
}
}
protected void btnNew_Click(object sender, EventArgs e)
{
connfordata.Open();
SqlCommand cmdfrexesp = new SqlCommand("sp_SRXO_InsDocTemplate", connfordata);
cmdfrexesp.Parameters.AddWithValue("@W113_CompanyID", 5);
cmdfrexesp.Parameters.AddWithValue("@W113_WebstoreID", 23);
cmdfrexesp.Parameters.Add("@W113_XMLID", SqlDbType.Int).Direction = ParameterDirection.Output;
cmdfrexesp.CommandType = CommandType.StoredProcedure;
cmdfrexesp.ExecuteNonQuery();
int yourResult = Convert.ToInt32(cmdfrexesp.Parameters["@W113_XMLID"].Value);
connfordata.Close();
txtCurrentOrder.Text = yourResult.ToString();
}
如果您不介意的话我想建议您
1.为你提交一个单独的方法提交功能
2.只要你需要
3,你就可以在页面加载时调用相同的方法,在按钮点击时调用此方法页面refereshed。
因此,创建一个方法并调用该方法而不是按钮单击。
If you don't mind then I would like to suggest you that
1. create a separate method for you submit function functionality
2. Call this method on the button click whenever you need
3 and Same method you can call on page load when page refereshed.
So create a method and call that method instead of button click.
这篇关于即使我没有点击它,按钮事件也会自动触发。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!