Questions tagged [custom-server-controls]

Custom server controls allow you to create entirely new controls for use with ASP.NET or to derive from existing controls and extend or modify their functionality.

A custom server control is, in its essence, a class that derives from either the Control or WebControl class of the System.Web.UI namespace, or from one of the classes that derive from these controls. Custom server controls can be used in your ASP.NET Web Forms pages in very much the same way you use the built-in server controls that come with ASP.NET. There are two primary categories of custom server controls:

Rendered controls

Rendered controls consist largely of custom rendering of the text, tags, and any other output you desire, which may be combined with the rendered output of any base class your control is derived from. Rendered controls override the Render method of the control they derive from. This method is called automatically by the page containing the control when it's time for the control output to be displayed.

Compositional controls

Compositional controls get their name from the fact that they are composed of existing controls whose rendered output forms the UI of the custom control. Compositional controls create their constituent controls by overriding the CreateChildControls method of the control they derive from. This method, like the Render method, is automatically called by ASP.NET at the appropriate time.

Text taken from http://oreilly.com/catalog/aspdotnetnut/chapter/ch06.html

287 questions
65
votes
12 answers

Dropdownlist control with s for asp.net (webforms)?

Can anyone recommend a dropdownlist control for asp.net (3.5) that can render option groups? Thanks
Nick
  • 5,616
  • 10
  • 52
  • 72
26
votes
4 answers

How to register custom server control on ASP.NET page

I have a project and I am trying to register a custom server control (there is no .ascx file) on the page. I am currently using Class Declaration namespace MyApp.Controls{ public class CustomControl: WebControl{ public string Text …
12
votes
1 answer

How do you build an ASP.NET custom control with a collection property?

I'm looking to do something akin to What's the bare bones code needed to pull this off? Rick's example shows something akin to…
Larsenal
  • 49,878
  • 43
  • 152
  • 220
11
votes
5 answers

ASP.NET / C#: DropDownList SelectedIndexChanged in server control not firing

I'm creating a server control that basically binds two dropdown lists, one for country and one for state, and updates the state dropdown on the country's selectedindexchanged event. However, it's not posting back. Any ideas why? Bonus points for…
10
votes
1 answer

ASP.NET Server Control - How to add AssemblyInfo file

I've noticed on a few tutorials online that when a new ASP.NET Server Control is added, it automatically includes Properties folder (containing AssemblyInfo.cs) and a References folder. This works fine for me when creating a C# Server Control, but…
Curtis
  • 101,612
  • 66
  • 270
  • 352
10
votes
3 answers

How to take control of style sheets in ASP.NET Themes with the StylePlaceHolder and Style control

Update: This turned into a blog post, with updated links and code, over at my blog: https://egilhansen.com/2008/12/01/how-to-take-control-of-style-sheets-in-asp-net-themes-with-the-styleplaceholder-and-style-control/ The problem is pretty simple.…
Egil Hansen
  • 15,028
  • 8
  • 37
  • 54
9
votes
3 answers

ASP.NET Custom Control - What is the best way to include embedded CSS reference only once?

The problem: I am embedding a CSS file into a custom control library with several controls. I want to share the same CSS file for all of the controls regardless of how many instances of them are on a given form. When more than one control is on the…
NightOwl888
  • 55,572
  • 24
  • 139
  • 212
9
votes
4 answers

ASP Nested Tags in a Custom User Control

I'm just getting started with Custom User Controls in C# and I'm wondering if there are any examples out there of how to write one which accepts nested tags? For example, when you create an asp:repeater you can add a nested tag for itemtemplate.
Static Tony
  • 224
  • 1
  • 3
  • 8
8
votes
4 answers

How Do I Change the render behavior of my custom control from being a span

When writing a custom control it always rendered as an HTML span element. How can I change it for example to a div?
Kasrak
  • 1,509
  • 4
  • 24
  • 48
6
votes
6 answers

Custom Server Control causes full postbacks inside of UpdatePanel

I have a custom server control that seems to work fine until I put it in an UpdatePanel. Once inside the UpdatePanel it continues to work fine but the UpdatePanel now does full postbacks when my custom server control does a postback. Do I need to…
6
votes
3 answers

ASP.NET 2.0 add styles dynamically to page in a control

I need to add to the page from within a custom control. I can't use a stylesheet (.css) because I'm using a url(...) and need to resolve the url. Right now I'm doing: Page.Header.Controls.Add(new LiteralControl("