Steve C. Orr

Software Engineer, Web Developer, Database Designer
 
  

 







Q: Why don't any controls show up on my page at run time?

A: A problem people often come across when setting up a machine for ASP.NET is that the controls don't show up on the page at run time. A common symptom is that Label values show up on the page, but other controls, such as Buttons and TextBoxes, do not. Most of the time the problem is that your IIS mappings aren't set. One way this can happen is by installing IIS after the .NET Framework has been installed. Luckily, this situation is easily remedied. To repair the mappings, simply run "aspnet_regiis.exe" with the "-i" command line parameter. This program can be found within the Windows directory under the Microsoft.NET\Framework\version folder. In other words, for a .NET 1.0 Web application, you'd likely need to run this from the command prompt:

C:\Windows\Microsoft.NET\Framework\v1.0.3705\ASPNET_REGIIS.EXE -i

For a .NET 1.1 Web application, the default path is:

C:\Windows\Microsoft.NET\Framework\v1.1.4322\ASPNET_REGIIS.EXE -i

For a .NET 2.0 Web application, the default path is:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\ASPNET_REGIIS.EXE -i

Here's more information.


Q: What is a Server Control?

A: In short, a server control is any control that has the runat="server" attribute in the definition. The job of such a component is to render HTML to the output stream of a Web page. All server controls inherit directly or indirectly from System.Web.UI.Control. All the standard controls in the Web Forms tab of your Visual Studio.NET toolbox are server controls. This means that you can interact with them from the server-side code in the code-behind file of the page, manipulate properties of the control from code, call methods of the control, and respond to server-side events raised by the control.

A control dragged onto a form from the HTML tab of the Visual Studio.NET toolbox is not a server control by default, but can easily be turned it into one by right clicking on the control and selecting Run As Server Control. This action simply adds the runat="server" attribute to the control. Placing an HTML control on a page without the runat="server" attribute would render the control on the page at run time just the same as any control, but it could not be directly manipulated via server-side code. Performance benefits will be gained from not using a server control when a control doesn't need to be manipulated from server-side code, because that's one less control the server needs to instantiate.


Q: What's the difference between HTML controls and Web controls?

A: In the Visual Studio.NET toolbox there is a tab for HTML controls, and another tab for Web controls. Many of the controls found in the HTML tab have a similar, roughly equivalent, control in the Web controls tab. When an HTML control is dragged onto a Web form, it's represented in your ASPX with code such as this:

<IMG src="MyImage.jpg">

A Web control will look more like this:

<asp:Image id="Image1" runat="server" ImageUrl="MyImage.jpg" />

HTML controls are quick and small and require little memory. Conversely, Web controls provide more advanced functionality than HTML controls.

You'll find the HTML controls to be intuitive and familiar if you're an old-school HTML Web developer. However, you're more likely to feel at home with the extra features that Web controls provide if you have more of a Windows/ActiveX development background. Why have two sets of similar controls? Microsoft didn't want to abandon developers with either background, so it made a set of controls for each. Freedom of choice is a wonderful thing.

Be aware that HTML controls were not designed to be especially extensible. Therefore, when making your own controls, you should instead inherit from WebControl or Control.


 

(advertisement)