RE: FindControl() on ASP.NET UserControl Objects



STeven, when I look in the code-behind for the user control, despite the fact
that the control is in a folder named "Controls", I have named the Class
"MyUC" (with no underscores or anything). I should be able to do that as long
as it's unique.

What's so weired is that sometimes the thing compiles and other times it
doesn't. Sometimes the Intellisense comes up and other times it doesn't.
Seems to be based on whether I've "touched" the files or not or something. I
have an ASPX which doesn't have a code-behind and the some code compiles
perfectly that way. If I run that page first then go back to VS and set the
ASPX *with* the code-behind as the Start Up page, then even *that* page runs
- unless I then go and touch the ASCX and then it stops working.

I tried the "VirtualPath" thing you suggested and still this is happening.

Yes, I would VERY much appreciate ti if you would create a very simple
sample with this structure:
/Default.aspx
/Default.aspx.cs (code-behind) - which uses the "MyUC" type in the code
somewhere
/Controls/MyUC.ascx
/Controls/MyUC.ascx.cs (code-behind)

Your help is MUCH appreciated!

Alex


"Steven Cheng[MSFT]" wrote:

Hi Alex,

For the type missing issue you met, I agree that adding a reference
directive in your aspx page(which use the usercontrols) is the reasonable
approach. I'm not sure about how your codebehind is written and whether is
your ascx usercontrol put(in a sub folder?). I think there are some other
things you can check:

1. Try using the "@Reference" directive with "VirtualPath" attribute to
specify the usercontrol reference. e.g.

=================
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testcode.aspx.cs"
Inherits="test_testcode" %>

<%@ Register Src="../uc/HelloWorldUC.ascx" TagName="HelloWorldUC"
TagPrefix="uc1" %>

<%@ Reference VirtualPath="~/uc/HelloWorldUC.ascx" %>
====================

Then, in you codebehind use VS IDE intellisense to get the usercontrol
instance to see whether you can correctly use intellisense to navigate all
the public members of the usercontro class.



2. ASP.NET 2.0 Will use folder hierarchy to naming the usercontrol's
codebehind class. e.g.

if you have a usercontrol named "HelloWorldUC.ascx" and put it in a sub
folder, the codebehind class name will become:

public partial class uc_HelloWorldUC : System.Web.UI.UserControl
{

So you can also verify whether you've used the correct class name(identical
to the one in the ascx usercontrol's codebehind file) in your main page.


If you feel necessary, I can also send you a set of test page and control
for your reference.

Please feel free to post here if you have any questions.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.



.



Relevant Pages

  • Re: "The system cannot find the file specified" appears peridically in runtime
    ... As for your questions - pix:DispOfficeMajor is indeed the usercontrol. ... before - the control is perfectly compiled. ... "public" part, root folder of the website - in which that control resides, ... As for your second suggestion - Reference problem. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Delegate for control embedded into MFC
    ... Control Library project and a UserControl in this project. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Winform inside a SplitContainer Funny Behaviour
    ... Since all the textbox controls on our forms are usercontrol (inheriting ... Group control as well. ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework.windowsforms)
  • RE: How to enable IME on a custom UserControl?
    ... We don’t put any child controls on the user control. ... I create a Windows application project and add a UserControl into the ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.general)
  • RE: apply an ItemTemplate dinamically
    ... databound control. ... Such ITemplate property is designed to be configured ... usercontrol and add the usercontrol into ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)