Powered by Blogger.

Sunday, February 23, 2014

How To Call a Button Click From Another Button in C#.Net?



In this post we will discuss about how we can call a button click from another button click in C#.Net. Remember this is available in windows application not in web application.

Also check out:

- JavaScript runtime error: Automation server can't create object

- List all Stored Procedure Created and Modified in Last N Days in SQL Server 2008

- Serialization and Deserialization in Remoting in C#.Net

It is easy to call a button click on another button click. Check the full code below:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnFirst_Click(object sender, EventArgs e)
        {
            lblResult.Text = "This is the First Button!";
        }

        private void btnSecond_Click(object sender, EventArgs e)
        {
            btnFirst.PerformClick();
        }
    }
}

Here in the second button click event we are calling the first button click and the result will be shown as "This is the First Button!". Check the figure for output.




0 comments

Post a Comment