Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 September 10th, 2004, 06:35 AM
Authorized User
 
Join Date: Jun 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default In The Dark with Visual Studio Control Compilation

Hi All,
I have written and compiled the DataAccesscomponent including the code for 'GetMotd' successfully, however I have an error when compiling the code for my CustomMotdControl? Page498
In VS there is an option to add components, Web User Controls and Class objects among others, I have tried the Control code in all three options none of which will compile, I currently have the code in a class.vb file and get the following message from the command prompt:

C:\BegASPNET11\WroxUnited\CustomMotdControl.vb(33) : error BC30466: Namespace or type 'DataAccesscode' for the Imports 'WroxUnited1.WroxUnited.DataAccessCode cannot be found. (it is in the same directory and also in the Project References bin)?
Imports WroxUnited1.WroxUnited.DataAccesscode.

The class CustomMotdControl.vb code is as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~

Imports System
Imports System.Collections
Imports System.Web.UI

Namespace WroxUnited

    Public Class CustomMotdControl
        Inherits System.Web.UI.Control

        Private _name As String = "MOTD"
        Public Property Name() As String
            Get
                Return _name
            End Get
            Set(ByVal Value As String)
                _name = Value
            End Set
        End Property
        Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
            Dim data As New WroxUnited.DataAccessCode
            Dim motdMessages As New ArrayList

            motdMessages = data.GetMotd()
            writer.Write("<div class='motd'>" & _name & ", " & DateTime.Now.ToShortDateString() & ": <br/>")

            Dim message As String
            For Each message In motdMessages
                writer.Write(message & "<br>")
            Next

            writer.Write("</Div>")
        End Sub
    End Class
End Namespace

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~

I have tried adding to the Imports:
'Imports WroxUnited1.WroxUnited.DataAccessCode' and
inside the class - 'Public Data As New WroxUnited1.WroxUnited.DataAccessCode'
Which I had had to do to make the DataAccessCode visible in the Default.aspx.vb file but to no avail.
NOTE: there is no problem with the line motdMessages = data.GetMotd() which suggests that it can see the DataAccessCode?
Any suggestions for getting rid of the comilation error?
Thanks in anticipation,
Edward,

 
Old September 10th, 2004, 02:12 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Do you have the definition for DataAccessCode? Is it declared with an access-level that your app won't be able to see (such as Protected or Friend)?

Brian
 
Old September 10th, 2004, 02:19 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Edward,

Did you add the Data Access vb file to the same project in VS.NET using Add Existing Item as I suggested in an earlier thread?

If you do so, there is no need to add a reference. All you would need is something like Imports MyDataAccessCode, assuming that's the Namespace scop of the DataAccess class.....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old September 11th, 2004, 08:37 AM
Authorized User
 
Join Date: Jun 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Brian, thanks for your reply to my topic.
Definition for DataAccessCode? No – I don’t think so? My internal Functions are all Public none are Private or Protected but is this definition to do with a setting of DataAccessCode.dll in the compiler? If so there is nothing in the .bat file to set or change this property.
Would you like to clarify this point?
Many thanks,

Edward.

 
Old September 11th, 2004, 08:43 AM
Authorized User
 
Join Date: Jun 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi again Imar, thanks for your patience.
I confess that I didn’t add the DataAccess.vb file to the original project from the supplementary project included in my WroxUnited1 project, as suggested in the earlier thread, it was already there having initially been built in the original project, though I did try to apply your suggestion and investigated its potential.
The file I want read in other files is the DataAccessCode.dll this was successfully achieved for reading by the pages Default.aspx and Teams.aspx, (despite the two errors mentioned in the other thread) when we move on to reading it in the CustomMotdControl all seems well until I try to compile the control when the error listed above appears!
The bit I don’t understand is that having added the new Function ‘GetMotd’ to the DataAccessCode and successfully recompiled it, that the code calling this function in the CustomMotdControl.vb is not underlined (with or without the ‘Imports WroxUnited1.WroxUnited.DataAccessCode’ line of code) and the tip appearing when the cursor is positioned over the ‘data.GetMotd()’ reads ‘Public Function GetMotd() As System.Collections.ArrayList’ as expected, suggesting all is well, that the GetMotd function has been found and can be read? Yet the control will not compile and the error message suggests otherwise (that it can’t be found)!
The Namespace is ‘WroxUnited’ and is listed between the dot operators in the ‘Imports WroxUnited1.WroxUnited.DataAccessCode’ line of code.
Any further suggestions?
Many thanks again, as always,

Edward

 
Old September 11th, 2004, 04:16 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

The problem is: I don't have the book and I don't have the downloaded code, so it's hard for me to tell what exactly is going wrong.

However, in response to your other topic I can say that the files you add are just templates. So, if you want to add a class with code from, say, a forum post, you can add a New Class in VS.NET, delete the default code that is present and then paste back in your new code.

Usually, the type of file you add just determines the default code. So, you could add a component, then remove all of its code, and past back in a Class definition. From that point on, the .VB file will be a class, and no longer a component.

So, in your case, I think the easiest thing to do is simply add the class file to your solution. You'll end up with something like this:

- My Solution
  - My Project
    + Default.aspx
    - MyOtherWebFile.aspx
      + MyOtherWebFile.aspx.vb
    - MyDataAccessFile.vb

This way, MyDataAccessFile is part of the project and solution and will share the same default namespace that VS.NET has assigned.

Now, let's assume the MyDataAccessFile file contains code like this:

Namespace MyWebproject.MyDataAccessStuff
  Class MyDataAccess

  End Class
End Namespace

With this code, pages in your web project can access the DataAccess code like this:

Imports MyWebproject.MyDataAccessStuff
Dim aDataAccess As New MyDataAccess()

or

Dim aDataAccess As New MyWebproject.MyDataAccessStuff.
MyDataAccess()

If they are all part of the same project, there is no need to add a reference, not to a DLL and not to a project. All code will be compiled to the same assembly.

With this setup, you don't need additional batch files with compile instructions, no additional assemblies, and no hassle with other files outside the solution.

If you want to put MyDataAccess in a separate project so you can reuse it in other applications, just add a Class Library to your Solution, add the MyDataAccessFile.vb to that project and then add a Project Reference in your Wen project to this new Class Library.

When you have VS.NET, I really don't see the point of fooling around with command line compile stuff, and all this other DLL hell you got yourself.

VS.NET can make this very easy for you; you just have to play by its rules......

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Overdue by Muse (Track 11 from the album: Showbiz) What's This?
 
Old September 13th, 2004, 08:54 AM
Authorized User
 
Join Date: Jun 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar, thanks again for your response, it is truly appreciated.
I can guess that it must be a problem answering queries on the content of a book when you don't have a copy! I have a copy and believe me I can't tell exactly what is going wrong!

I thought I would address your paragraph2 and demonstrate the problems and errors generated by the other class templates empied of all default code then filled with the code from the book, but find that I cannot reproduce the errors previously experienced! I had a go with the template WebUsercontrol it appears OK but like the previous version using the Class template failed to compile - next I tried it with the Component template, then lo and behold it compiles?*@! The component template was a template I had previously tried and had errors with missing references to 'ComponentModel' this error is absent this time. In Mechanical Engineering terms this is an intermittent fault (the very worst to locate).

You will by now be tearing your hair out! Why is he still trying to compile this D~~~ Class template!, I can hear you say. Well I want to load this compiled control onto the default, page much as I might load a label. Only surprise surprise the Tag listed in the book doesn't work!!! Sugar.

If I followed your suggestion what I might end up with is a list of messages, which I would then have to display in say a label on the Default.aspx page, but the exercise is a custom built control.

This book is my first purchased for ASP.NET, there is no mention on the cover of Web Matrix and had I known the about all this DLL hell I got myself, I would not have bought it - but I am stuck with it. I searched around for other examples and eventually got enough insight to break into chapter 4 much of the stuff before is unrelated to VS.NET, thereafter I have been reading between the lines, it could have been easier if I knew what the VS.NET rules were.

Not all Wrox books are this bad, I have a number on my book self, Mathew Rennolds 'Beginning E-Commerce' was the very best programming book ever, but it was ASP6.

I am continuing the saga with a new Topic! Read your responses there?
Many thanks to you Imar, I appreciate having someone to bounce these problems off of.
All the best,

Edward.

 
Old September 13th, 2004, 01:53 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I think you shouldn't blame the book too much. After all, it was *you* who decided to use a different tool than described in the book.
Especially with a complex tool like VS.NET this can quickly lead to problems.

Web Matrix and VS.NET are two different beast. Not only in their target audience, but also in the way they operate. Code Behind, compiled class libraries, etc make those two IDEs very different from each other.

Are you still having troubles with things? What do you mean with DataAccess component that has a tag? Is the DataAccess supposed to be added to the markup side of the page? What is the functionality of this control?

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old September 16th, 2004, 07:31 AM
Authorized User
 
Join Date: Jun 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar, thanks for your reply.
Not so, I had first to justify to my purse holder the worth of upgrading to VS.Net before considering a book. I had placed my order for the upgrade prior to receiving an email from Wrox advertising the fourth comming publication of the book ASP.NET1.1 through Bookpool, it actually cost more from them than it would have cost had I purchased it from the local book store (because of the freight charges, also I would have had a chance to handle it and check if it suited my needs). I did not know that there was such a thing as Web Matrix and had I known that the book used this as the application means of writing the code, as other books do, I would *not* have purchased it! I would like to have changed the book at the time of receipt but Wrox were not interested. So I am wrestling with 'all this other DLL hell I got myself' as you so rightly said.
IS> Are you still having troubles with things? No page is without a problem (I have frequently been able to make adjustments to get VS to accept the code) but the error messages are not always helpful in deciding what requires changing.
I have a DataAccessCode component compiled and working OK its inclusion into the control has been problematical due to the control taking three attempts to compile with no change in content but eventually compiling, this is still subject to test if and when the control is recognised by VS for inclusion onto the Default page.
Please note it is a control that I am trying to add to the front page of Default.aspx, first using a resgister tag followed further down the page with a <WroxUnitedMotd: > tag. The function of this control is to show how to build Custom Controls (it happens to display UpComming games from the database), I have sent images of pages 498 and 499 from the book to clarify the book content relating to the comments in this topic.
Assuring you of my appreciation for any help to clarify the book content in the format of VS.

Edward.


 
Old September 16th, 2004, 01:38 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Like I think I said in an earlier thread, you can still use Web Matrix concepts in Visual Studio. So, you can still manually create an assembly and use it in a page.

Here's what I did to make it work:

1. Added the code from page 498 to a file called Test.vb (I left out the stuff about DataAccessCode as I didn't have the class for that code. All I did was override the sub Render, and outputted a message, including the Name property.)

2. Compiled the class into an assembly with this batch file:
Code:
vbc /t:Library /r:System.dll,System.Web.dll /out:CustomMotDControl.dll Test.vb
3. Copied the resulting .dll file to the /bin folder of my Web application.

3. Added a new Web Form to my application.

4. Added the following register directive:
Code:
<%@ Register TagPrefix="WroxUnitedMotD" Namespace="WroxUnited" Assembly="CustomMotdControl" %>
5. Added the following code to my page:
Code:
<WroxUnitedMotD:MotDControl id="wuMord" Name="Everyone is unique, except for me."
        runat="Server"></WroxUnitedMotD:MotDControl>
        6. Ran the page in my browser. Voila: instant Hello World of a user control.

Doesn't this happen when you ran your code? Maybe you're getting confused about imports and references in Visual Studio .NET. Notice that I didn't do anything like that; all I did was copy the .dll to my Bin folder.

Does this help?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Something Against You by Pixies (Track 3 from the album: Surfer Rosa & Come On Pilgrim) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Studio 2005 compilation error manjupspl Visual C++ 2005 0 April 23rd, 2007 02:04 AM
Visual Studio 2003 vs. Visual Studio 2005 eitanbarazani C# 2005 4 May 9th, 2006 01:34 AM
Visual Studio .net2003 and Visual Studio 2005 Gert Visual C++ 1 January 24th, 2006 05:10 AM





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