Create Dynamic controls with events:- we can create the events through addhandler and remove the events through RemoveHandler.For Example we can add the dynamic button and remove the events at runtime
Partial Class _Default Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim btnAddHandler As New Button btnAddHandler.Text = "AddHandler" form1.Controls.Add(btnAddHandler) AddHandler btnAddHandler.Click, AddressOf btnaddhandler_Click RemoveHandler Button1.Click, AddressOf Button1_Click
End Sub
Protected Sub btnaddhandler_Click(ByVal sender As Object, ByVal e As System.EventArgs) Response.Write("Addhandler") End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Write("Remove Handler") End Sub End Class
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Text="Remove" /> </div> </form> </body> </html>
|
No responses found. Be the first to respond and make money from revenue sharing program.
|