C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET WebForms »

Add Handler and Remove Handler at Runtime


Posted Date: 02 Jul 2009    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: UltimateRenganMember Level: Diamond    
Rating: 1 out of 5Points: 10



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>




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Add Handler and Remove Handler at Runtime  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Dynamic DataGrid
Previous Resource: Read Line by Line From Text File in Dot Net
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use