aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies Dynamic button click event in c#

Jul 30, 2012
In this article I will explain how to implement dynamic button click events in using c# or

In previous posts I explained
how to create controls dynamically in and save dynamic control values in database and many articles relating to, JQuery, and SQL etc. Now I will explain how to handle dynamic button click events in using c# or for that first we need to write the following code in your aspx page

<html xmlns="">
<head id="Head1" runat="server">
<title>Create controls dynamically in and handle button click events</title>
<form id="form2" runat="server">
<asp:Panel ID="pnlInfo" runat="server">
After completion of aspx page design add the following namespaces in code behind

C# Code

using System;
using System.Web.UI.WebControls;
After add namespaces write the following code in code behind like as shown below

protected void Page_Load(object sender, EventArgs e)
Button btnSubmit = new Button();
btnSubmit.ID = "btnSubmit";
btnSubmit.Text = "Submit";
btnSubmit.Click += new System.EventHandler(btnSubmit_click);
// Dynamic button click event
protected void btnSubmit_click(object sender, EventArgs e)
Response.Write("you clicked on button");

Imports System.Web.UI.WebControls
Partial Class Default3
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim btnSubmit As New Button()
btnSubmit.ID = "btnSubmit"
btnSubmit.Text = "Submit"
AddHandler btnSubmit.Click, AddressOf btnSubmit_click
End Sub
' Dynamic button click event
Protected Sub btnSubmit_click(ByVal sender As Object, ByVal e As EventArgs)
Response.Write("you clicked on button")
End Sub
End Class
For more details check below posts

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


kavinraj said...

hi suresh its very good experience by learning your blog..can u post any article reg Globalisation and Localisation if you have

athul dk said...

Hello, i created a dynamic button and a click event,its working, but on that click event i created one more button and its event is not working. Please help me(

void DynamicButton()
//Button1 is created
clickevent1 is created

//Button2 is created
//clickevent 2 is created


Rajkumar Palnati said...


HtmlImage image = new HtmlImage();

for this html control how can i create the event handler dynamically ?

Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.