Use custom events (with parameters) in Asp.net)

Source: Internet
Author: User

// 1. first, define a parameter class
Public partial class sayeventargs: eventargs
{< br> Public string username;
Public string websiteurl;
}

//2. Define a delegate
Public Delegate VoidSayeventhandler (ObjectSender, sayeventargs E );

//3. Define an event
Public EventSayeventhandler sayevent;

//4. Events
Public VoidOnsayevent (sayeventargs E)
{
If(Sayevent! = Null)
{
Sayevent (This, E );
}
}

// 5. Passing parameter functions
Public   Void Loginsite (string username, string websiteurl)
{
Sayeventargs E =   New Sayeventargs ();
E. Username = Username;
E. websiteurl = Websiteurl;
Label1.text = E. Username +   " <Br> " ;
Label1.text + =   " Welcome to <a href = "   + E. websiteurl +   " > Xiaoxuan " ;
Onsayevent (E );
}

// 6. functions to be delegated
Public   Void Saysomething ( Object Sender, sayeventargs E)
{
Label2.text = E. Username + " Note: <br> In this blog <a href = "   + E. websiteurl +   " > Xiaoxuan listening to xiaoxuan in the rain and night </a> level, it is not necessary for you to talk about wild things, but it will be used as a proof-of-concept in the future. OK? " ;
}

//7. Create a delegated instance
Sayevent+ = NewSayeventhandler (saysomething );

Loginsite ("Hazelnut","U/admin/index.html");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.