Write a program to create a user control with name and surname as data members and login as method and also the code to call it. (Hint use event delegates) Practical Example of Passing an Events to delegates



Write a program to create a user control with name and surname as data members and login as method a..

Answer / Pawan Kumar Verma

"Creating a UserControl in C# involves defining a class that inherits from System.Web.UI.UserControl, and defining properties for your data members such as Name and Surname. Here is an example:nn```csharpnpublic partial class MyUserControl : System.Web.UI.UserControl {n public string Name {n get {n return (string)ViewState["Name"];n }n set {n ViewState["Name"] = value;n }n }n public string Surname {n get {n return (string)ViewState["Surname"];n }n set {n ViewState["Surname"] = value;n }n }n protected void Page_Load(object sender, EventArgs e) {n // Initialize controls heren }n public event EventHandler LoginEvent;n protected void Button1_Click(object sender, EventArgs e) {n if (ValidateLogin()) {n OnLogin();n }n }n private bool ValidateLogin() {n // Validation logic heren return true; // Replace with actual validationn }n protected virtual void OnLogin() {n if (LoginEvent != null) {n LoginEvent(this, EventArgs.Empty);n }n }n}"

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

What's the difference between a method and a procedure?

1 Answers  


What is c# best for?

1 Answers  


What is short circuit logical evaluation?

1 Answers   TCS,


What is the use of jit ? Jit (just - in - time) is a compiler which converts msil code to

1 Answers  


What is multiple interface in c#?

1 Answers  


How do I run managed code in a process?

1 Answers  


public void A() { int x; x = 8; x *= 4 + 8 / 2; } Given the above code, what is the value of "x"?

8 Answers  


Can hashtable have duplicate keys in c#?

1 Answers  


Can we write one page in c# and other in vb in one application ?

3 Answers   Keane India Ltd,


What is window application in c#?

1 Answers  


Why do we use struct in c#?

1 Answers  


What are satellite assemblies? How will you get the different language strings?

1 Answers  


Categories