Rendering a derived control in design view (VS2005)

P

postings

Hi

The code below compiles and works. It's a control derived from a drop
down list that displays countries for the user to select.
My issue is that is I look in the drop down list in Design view of
Visual Studio 2005 (final), rather than rendering the dropdownlist, it
renders a gray box displaying:
"Error Creating Control - ddlCountry, object reference not set to an
instance of an object."

Is this normal? Could somebody give me a pointer on how I can render
this control?
Code below.

Many thanks

Alex

---------------------------------------------------->

Imports Microsoft.VisualBasic

Namespace Testing
Public Class ddlCountry
Inherits DropDownList

Public Sub New()
Me.Items.Add(New ListItem("Select a Country", "0"))
Dim Connection As New
SqlConnection(ConfigurationManager.ConnectionStrings("MainConnStr").ConnectionString)
Connection.Open()
Dim command As New SqlCommand("SELECT CountryID, Country
FROM Countries ORDER BY Country", Connection)
Dim reader As SqlDataReader = command.ExecuteReader
While reader.Read
Me.Items.Add(New ListItem(reader.GetString(1),
reader.GetString(0)))
End While
reader.Close()
Connection.Close()
End Sub
End Class
End Namespace

<---------------------------------------------------->

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb"
Inherits="test" %>
<%@ Register Namespace="Testing" TagPrefix="MyControl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<Mycontrol:ddlCountry runat="server" ID="ddlCountry"/>
</form>

</body>
</html>

<----------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top