Wrox Programmer Forums
|
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 January 19th, 2004, 09:42 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default User Control Access

I am having issues with setting properties of a user control during Page_Load of the hosting page. My attempts are usually met with "Control not declared" or "Object reference not set to an instance of an object".

The user control is just a label (just for testing - I will be doing much more later on). I have added one public property called LabelText. It is registered properly:
<%@ Register TagPrefix="uc1" TagName="MyUserControl" Src="MyUserControl.ascx" %>

In the HTML, I can set this property at design time with no problem. However, in the page load event, I try to do something like MyUserControl1.LabelText = "test" and I am met with one of the errors listed above. I have used the declaration "Dim MyUserControl1 as MyUserControl" to the same effect.

According to gotdotnet http://samples.gotdotnet.com/quickst...bpagelets.aspx
setting the properties should be strightforward. What am I missing?

Eventually, this will be a dynamic navigation panel - but I will need to set nav links at page load time.

Thanks in advance,
Colonel

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old January 19th, 2004, 09:53 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, "after further review", another thread shed some light on the subject. I dragged and dropped on to the page with VS.NET, but the user control was never declared along with the host form's controls.

That is, I added
Protected WithEvents MyUserControl1 As MyUserControl

Now, I have access as I thought I would.

Being self conscious and in need of affirmation, I would appreciate any comments on this solution.

Thanks again,
Colonel

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old January 20th, 2004, 04:03 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

This is a known issue with Visual Studio .NET. It should add a declaration for the control in the Code Behind, just as it does with server controls.

Your work-around is the way to go; that is, you'll need to add the declaration yourself.

Check this article for more information.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 20th, 2004, 10:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I have found that if I close the page and open it again that VS.NET then adds it to the code behind.

The problem has been fixed for VS.NET 2003 which I now have.

 
Old January 20th, 2004, 10:35 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your comments. (Dank U, Imar)

I believe I am using VS.NET Studio 2003, and I had closed the page and reopened to no effect. Have you patched Studio at all?

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old January 20th, 2004, 12:04 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Graag gedaan ;)

It indeed seems fixed in Visual Studio 2003. When you switch between Code View and Design View, VS adds the declaration for the control for you. (And then you spend the next 5 minutes fixing the HTML that VS screwed up).

The article says that the problem applies to VS .NET 2003 as well, but that seems not to be the case. The link to the article got messed up. Somehow the ; between the items were removed (bug in the forum?). Here's the link again: http://support.microsoft.com/default...316370&GSSNB=1

AFAIK, there are no patches available for VS .NET. I use the Check for an Update feature every now and then, but it never said there was an update. I guess Microsoft just publishes a new major release instead of a service pack ;)

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Access User Control gridview gergi67 C# 2 November 9th, 2007 11:09 AM
Add Windows User control in Web User Control agarwalvidhu C# 0 March 30th, 2006 01:17 AM
Help! Custom Server Control using User Control diehard ASP.NET 1.0 and 1.1 Professional 2 January 4th, 2006 12:33 PM
Help with control initialization in user control mike_remember ASP.NET 1.0 and 1.1 Professional 7 December 19th, 2005 11:08 AM
Access a web user control from javascript? shenku ASP.NET 1.0 and 1.1 Professional 3 July 21st, 2005 07:24 AM





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