Hi,
How To Use Delegate In Asp.Net?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 12, 2012, 7:46 PM EDT
A delegate is a class that can hold a reference to a method.A delegate is equivalent to a type-safe function pointer or a callback.The delegate is used to declare a reference type that can be used to encapsulate a named or an anonymous method.
In asp.net we are using delegates to create custom events for custom controls.
Please refer
http://www.codeproject.com/Articles/13607/A-Beginner-s-Guide-to-Delegates
Use of Delegate in asp.net.
http://weblogs.asp.net/bhaskarghosh/archive/2008/07/10/custom-control-postback-and-events.aspx
hope this will help you.
Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 12, 2012, 9:13 PM EDT
In Vb.net
Delegates: - It is a procedure pointer, which stores the memory address of another procedure. It can be applied with
1.Sub procedure
2.Function procedure
But not property procedure.
Program
Ex1
Public Class Form1
Delegate Sub abhisek(ByVal x As Integer, ByVal y As Integer)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As abhisek
a = AddressOf rajiv
a.Invoke(10, 20)
End Sub
Public Sub rajiv(ByVal x As Integer, ByVal y As Integer)
Dim z As Integer
z = x + y
MsgBox(z)
End Sub
End Class
Ex2
Public Class Form2
Delegate Sub raj(ByVal x As String)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As raj
x = AddressOf rajiv
x.Invoke("Adarsh kumar")
End Sub
Private Sub rajiv(ByVal s As String)
MsgBox("Hello:" & s)
End Sub
End Class
Thankstom linker86 reputationPosted Jul 18, 2012, 1:45 AM EDT
Please Give me an example in ASP.NET