buba
buba

Reputation: 59

check if button is clicked in if() condition aspx.net

I want to check if btnTest_Click is clicked in another Button6_Click event.Below is my code.....Please help

   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()

  }

Upvotes: 0

Views: 1090

Answers (2)

Kevin
Kevin

Reputation: 7309

I would declare a class level boolean called testPassed.

Set it to false in the onload event if it is not a Postback.

Set it to true in the btnTest_Click event handler

Edit to add an example:

    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)

  }

Upvotes: 0

Dave Becker
Dave Becker

Reputation: 1433

as per Kevin's answer but instead of:

protected bool testPassed;

Have this:

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

By accessing the value of this property via view state the value will persist between requests.

Upvotes: 1

Related Questions