By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,905 Members | 1,630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,905 IT Pros & Developers. It's quick & easy.

Rendering a derived control in design view (VS2005)

P: n/a
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.ConnectionStrin gs("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>

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

Feb 1 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.