检查if()条件aspx.net中是否单击了按钮

时间:2015-01-29 13:39:37

标签: asp.net

我想检查btnTest_Click是否在另一个Button6_Click事件中被点击.Below是我的代码.....请帮忙

   protected void btnTest_Click(object sender, EventArgs e)
    {

        Session["Counter1"] = newValue;
        Session["Counter"] = newValue;
        if (Session["Markici"] != null || Session["Markici"] != null)
        {

            var clickedRow = ((Button)sender).NamingContainer as GridViewRow;
            var clickedIndex = clickedRow.RowIndex;

            /*decimal*/ old = dtCurrentTable.Rows[clickedIndex].Field<decimal>("Kolicina");

            decimal oldIznos = dtCurrentTable.Rows[clickedIndex].Field<decimal>("VkIznos");
            decimal VkDanok = dtCurrentTable.Rows[clickedIndex].Field<decimal>("VkDanok");
            string Cena1 = dtCurrentTable.Rows[clickedIndex].Field<string>("Cena1");
            int TarifaID = dtCurrentTable.Rows[clickedIndex].Field<Int16>("TarifaID");
}

 protected void Button6_Click(object sender, EventArgs e)
    {
    // how to check here if btnTest_Click is clickied
     if()

  }

2 个答案:

答案 0 :(得分:1)

根据Kevin的回答而不是:

protected bool testPassed;

有这个:

protected bool testPassed
{
    get { return (bool)ViewState["testpassed"]; }
    set { ViewState["testpassed"] = value; }
}

通过视图状态访问此属性的值,值将在请求之间保持不变。

答案 1 :(得分:0)

我会声明一个名为testPassed的类级布尔值。

如果onload事件不是Postback,则将其设置为false。

在btnTest_Click事件处理程序

中将其设置为true

编辑以添加示例:

    protected bool testPassed
    {
        get { return (bool)ViewState["testpassed"]; }
        set { ViewState["testpassed"] = value; }
    }
    protected override void OnLoad(EventArgs e)
    {
        if (!Page.IsPostBack)
        {
           testPassed=false;
        }
    }
    protected void btnTest_Click(object sender, EventArgs e)
    {

        Session["Counter1"] = newValue;
        Session["Counter"] = newValue;
        if (Session["Markici"] != null || Session["Markici"] != null)
        {

            var clickedRow = ((Button)sender).NamingContainer as GridViewRow;
            var clickedIndex = clickedRow.RowIndex;

            /*decimal*/ old = dtCurrentTable.Rows[clickedIndex].Field<decimal>("Kolicina");

            decimal oldIznos = dtCurrentTable.Rows[clickedIndex].Field<decimal>("VkIznos");
            decimal VkDanok = dtCurrentTable.Rows[clickedIndex].Field<decimal>("VkDanok");
            string Cena1 = dtCurrentTable.Rows[clickedIndex].Field<string>("Cena1");
            int TarifaID = dtCurrentTable.Rows[clickedIndex].Field<Int16>("TarifaID");
            testPassed=true;
}

    protected void Button6_Click(object sender, EventArgs e)
    {
    // how to check here if btnTest_Click is clickied
     if(testPassed)

  }