Hi,
How To Use Delegate In Asp.Net?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
tom linkerPosted Jul 18, 2012, 5:45 AM
Please Give me an example in ASP.NET
Satyapriya NayakPosted Jul 13, 2012, 1:13 AM
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
ThanksJignesh TrivediPosted Jul 12, 2012, 11:46 PM
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.