Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design 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 5th, 2005, 10:54 AM
Registered User
 
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm having the same problem with the usercontrol not being instantiated right away. Has anyone found a resolution for this?
 
Old January 13th, 2005, 09:30 PM
Registered User
 
Join Date: Jan 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have come across the same problem today and after a couple of hours have figured out the answer.
If for example your user control is called UC, then the Protected withevents line in your web form must be as follows

Protected WithEvents UR1 as UR

The reason has something to do with the fact that when the usercontrol is added to the webform, in the html view it is given an ID of UR1

 
Old January 18th, 2005, 03:56 PM
Registered User
 
Join Date: Jan 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote: I'm having the same problem with the usercontrol not being instantiated right away. Has anyone found a resolution for this?
I also am also having the same issue with a user control not being instantiated.

Symptoms:
I included a user control in the page:
Code:
<%@ Register TagPrefix="uc1" TagName="countControl" Src="countControl.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Count.aspx.vb" Inherits="InfraWare.Count"%>
 
    <body>
        <form id="Form1" method="post" runat="server">
            <P>
                <asp:Label id="lblClicked" runat="server">Counter not clicked</asp:Label></P>
            <P>
                <uc1:countControl id="counter" runat="server"></uc1:countControl></P>
        </form>
    </body>
</HTML>
And then attempted to use it in the "codebehind":
Code:
    Private WithEvents counter As countControl

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        lblClicked.Text = counter.ID
        lblClicked.Text += CType(counter.Number, String)
    End Sub
This gives the error: "Object reference not set to an instance of an object. " when I attempt to access the counter.

I beleive that planoie is right:

 
Quote:
quote: I trust there is an instance of this user control in the markup for this page. That's where the control is instantiated, so you don't need the New keyword in the codebehind.


But microsoft doesn't seem to agree... does anyone know what is going on here?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Windows User control in Web User Control agarwalvidhu C# 0 March 30th, 2006 01:17 AM
Web user control EvilGuyWhoEatsBrains General .NET 1 December 14th, 2004 01:21 PM
Web User Control Best Practices flyin General .NET 4 May 24th, 2004 07:57 AM
Web User Control Problem shmacgregor VS.NET 2002/2003 18 February 22nd, 2004 06:29 PM





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