How do I programatically change the color of a control
Use the properties BackColor and ForeColor. button1.BackColor = Color.White; button1.ForeColor = Color.Blue;
How can you create a check box dynamically in the server control?
usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Text; usingSystem.Web; usingSystem.Web.UI; usingSystem.Web.UI.WebControls; namespace WebCustomControl1 { [DefaultProperty(‘Text’)] [ToolboxData(‘<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>’)] public class WebCustomControl1 : WebControl { [Bindable(true)] [Category(‘Appearance’)] [DefaultValue(”)] [Localizable(true)] public string Text { get { String s = (String)ViewState[‘Text’]; return ((s == null) ? String.Empty : s); } set { ViewState[‘Text’] = value; } } protected override void CreateChildControls() { CheckBox blah = new CheckBox(); blah.Text = ‘CheckText’; blah.ID = ‘CheckValue’; this.Controls.Add(blah); } protected override void RenderContents(HtmlTextWriter writer) { this.EnsureChildControls(); this.RenderChildren(writer); } } }
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’/>
Why does my transparent Panel whose parent has a gradient background flicker a lot when resized?
Make sure to set these flags for your panel, in it’s constructor (for example). You will have to derive a class from Panel otherwise if you were initially using the Panel directly. class NonFlickerPanel : Panel { public NonFlickerPanel() { SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint,true); UpdateStyles(); } }