Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 31st, 2004, 02:04 PM
Authorized User
 
Join Date: Dec 2003
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default Set Custom Control Properites in Code-Behind

Good afternoon all,

In what seems like a never-ending quest to get my arms around ASP.NET I have new question. I am trying my hand at building a custom control, VERY basic in nature, to understand the concept. I am trying to use the Page_Load subroutine within a code-behind page to set two properties of the control. Despite my adding the control to the web-form, the code-behind page is not recognizing the control and I am getting "not-declared" errors. I have posted a code snippet below. Any help is appreciated.

Web-Form:
<%@ Register TagPrefix="myControls" Namespace="myControls" Assembly="ShowColor" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="DisplayShowColor.aspx.vb" Inherits="learn.DisplayShowColor"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>DisplayShowColor</title>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <myControls:ShowColor id="ctrlShowColor" Runat="server" />
    </body>
</HTML>

Code-Behind:
Public Class DisplayShowColor
    Inherits System.Web.UI.Page
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ctrlShowColor.Text = "Hello Ethan. Rise and Shine"
        ctrlShowColor.Color = "Orange"
    End Sub

End Class


Dolphin Bay, Inc. -- turning visions into eReality(tm) -- West Palm Beach, FL
Website Design, Internet Strategy, Search Engine Marketing

www.DolphinBay.biz
 
Old April 3rd, 2004, 08:35 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There is a problem with visual studio where adding a custom control (server or user control) to the form designer does NOT also add a declaration for that control in the code behind. So you will need to add it manually:

Protected WithEvents ctrlShowColor As myControls.ShowColor

You might need to change the control type.

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Server Control....Custom Property Editor ZArrinPour ASP.NET 1.0 and 1.1 Basics 1 June 15th, 2010 11:30 AM
Web Service, Custom Control, Custom Return Type robzyc ASP.NET 2.0 Basics 6 June 10th, 2008 08:03 AM
custom control inside custom control issues StevesonD ASP.NET 2.0 Professional 1 February 19th, 2008 06:54 PM
Adding code to a button inside a custom Control. Roinka ASP.NET 2.0 Basics 5 April 23rd, 2006 01:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.