Converting Single Page ASCX to use Codebehind, but server control definition not being generated....????

Dear All,

I have adopted some ASCX single page code which I want to convert to use CBH files for VB.NET code. The process I use to do this is to set the @Control directive as follows:

<%@ Control inherits="" codebehind="header.aspx.vb"%>

I save the file. I then right click on it in solution explorer and select 'View Code'. The CBH is then generated, but without the Server Control definitions. So I have to add them manually :

    Protected WithEvents signInOutMsg As System.Web.UI.WebControls.LinkButton


<asp:linkbutton style="FONT: 8pt verdana" id="signInOutMsg" runat="server" />

for example.

Any ideas please.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What happens when you click "View Code" before you do the code behind directive?
SamJollyAuthor Commented:
Have not tried this, but I have tried something else that works. Basically I saved/closed the page with the missing server control definitions then reopened the ascx and double clicked to reveal the CBH and eureka there is there are the definitions - found by accident. I am wondering whether this is one of VS2003's strange behaviours.

swapping between design view and html view sometimes works too
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

SamJollyAuthor Commented:
May be related to quirky VS2003, but if your CBH was inheriting from another class, would you expects the imports to be inherited as well e.g


Imports System
Imports System.Collections
Imports System.Web.UI
Imports System.Web.Security
Imports System.Configuration

Namespace IBuyAdventure

   Public Class PageBase


Public Class _default
    Inherits IBA.IBuyAdventure.PageBase

    "System.Web.Security.FormsAuthentication.SignOut()" will work not "FormsAuthentication.SignOut()"

Is this quirky behaviour or do you need to respecify the "Imports" statement for each vb file.


you will need to add the imports to the child class code file

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PeterFearn has the right idea, you have to go to design mode to have these created, and even then won't add references to your usercontrols.  Just keep Ctrl-Z handy when you go back to HTML view since will mangle your HTML.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.