How can you write events for the server controls?

using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebCustomControl1 { [DefaultProperty(“Text”)] [ToolboxData(“<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>”)] public class WebCustomControl1 : WebControl,IPostBackEventHandler { // Defines the Click event. public event EventHandler Click; //Invoke delegates registered with the Click event. protected virtual void OnClick(EventArgs e) { if (Click != null) { Click(this, e); } } // Define the method of IPostBackEventHandler that raises change events. public void RaisePostBackEvent(string eventArgument) { OnClick(new EventArgs()); } protected override void Render(HtmlTextWriter output) { output.Write(“<INPUT TYPE = submit name = ” + this.UniqueID + ” Value = ’Click Me’ />”); } } }

What is the Use of the Login Status Control?

The LoginStatus control will allow users to log out if they are currently logged in, and will display a link to the login page if they’re logged out. <asp:LoginStatus id=’ lsUser’ runat=’server’/>

What is an Associated ControlID?

This is the property defined for a Label control in 2.0, which provides linking to an interactive control such as textbox,button,listbox and other asp.net controls. It defines a hot key which moves the input focus to the control defined in the property. <asp:Label ID=’Label1′ runat=’server’ AssociatedControlID=’TextBox1′ Text=’Enter Ur Details’ Width=’86px’></asp:Label> <asp:TextBox ID=’TextBox1′ runat=’server’></asp:TextBox> In the above code, TextBox1 gets focused on clicking the Label1, sinced its AssociatedControlID is set to TextBox1.

How can an ListItem in the ListControl can be avoided from being displayed but it must remain in the collection?

In ASP.NET 2.0 List by setting Enabled=’False’ to the individual list item, entries avoids it from being displayed but it remains in the collection. It can be coded as below. <asp:ListBox ID=’ListBox1′ runat=’server’ > <asp:ListItem Enabled=’False’>Item 1</asp:ListItem> <asp:ListItem>Item 2</asp:ListItem> <asp:ListItem>Item 3</asp:ListItem> <asp:ListItem>Item 4</asp:ListItem> <asp:ListItem>Item 5</asp:ListItem> <asp:ListItem>Item 6</asp:ListItem> </asp:ListBox> Here Item1 remains in the collection but will not be displayed.