Re: .Net Newbie web user control question

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Craig (Craig_at_discussions.microsoft.com)
Date: 10/05/04


Date: Tue, 5 Oct 2004 14:03:04 -0700

I tried dragging the user control to the web form in design view, but it
didn't create a declaration for the user control. This is what shows up in
the auto generated in the code behind:

Public Class _default
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form
Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

"Robert Koritnik" wrote:

> Probably you didn't put your control as a protected (at least) declaration
> in the page's codebehind. When you have server controls in the ASPX and not
> declared in the codebehind, those controls don't get by any chance
> automaticly created in the codebehind.
>
> If you would use Design view instead of the HTML view of your page, the
> protected declaration would be automaticly created for you in the
> codebehind.
>
> --
> RobertK
> { Clever? No just smart. }
>
> "Craig" <Craig@discussions.microsoft.com> wrote in message
> news:46A877D9-82FA-4253-875A-AF2F7589EA2D@microsoft.com...
> > I'm having a problem calling a public method for a web user control. When
> I
> > reference the UC's id (MyTester) from within default.aspx.vb, I get a
> message
> > that the variable has not been declared. I'm posting the code below, can
> > anyone help out with this.
> >
> > the statement that throws the error is:
> > [default.aspx.vb]
> > MyTester.SetAppInfo(1001)
> >
> >
> > [default.aspx]
> > <%@ Register tagprefix="test" tagname="Message"
> > src="UserControls/tester.ascx" %>
> > <%@ Page Language="vb" AutoEventWireup="false"
> Codebehind="default.aspx.vb"
> > Inherits="MasterSite._default"%>
> > [snip]
> > <form id="Form1" method="post" runat="server">
> > <test:message id="MyTester" runat="server" />
> > </form>
> > [snip]
> >
> > [default.aspx.vb]
> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles MyBase.Load
> > MyTester.SetAppInfo(1001)
> > end Sub
> >
> >
> > [tester.ascx]
> > <%@ Control Language="vb" AutoEventWireup="false"
> > Codebehind="tester.ascx.vb" Inherits="MasterSite.tester"
> > TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
> > <asp:Label id="lblTester" runat="server"></asp:Label>
> >
> > [tester.ascx.vb]
> > Public Class tester
> > Inherits System.Web.UI.UserControl
> > Private _AppId As Integer
> > [snip]
> > Public Sub SetAppInfo(ByVal AppId As Integer)
> > 'do some biz logic here
> > _AppId = AppId
> > End Sub
> >
> > End Class
> >
>
>
>



Relevant Pages

  • Re: .Net Newbie web user control question
    ... > I tried dragging the user control to the web form in design view, ... > didn't create a declaration for the user control. ... Private Sub ... The following placeholder declaration is required by the Web ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: VS2005 and VS 6.0
    ... the class declaration. ... programmatically, using the message maps, overriding functions, etc. ... Reference library online for mfc in .net is maddening - has mfc itself ... the book "GUI Bloopers" was actually a design manual. ...
    (microsoft.public.vc.mfc)
  • Re: Designer problem with inherited user control
    ... accepts components at design time. ... "FunctionView" from View where I want to add more components at design ... the derived user control does not accept components when they are ...
    (microsoft.public.dotnet.framework.windowsforms.designtime)
  • Re: User Control Instance/DataGridView.Columns in Visual Studio De
    ... simple user control and a form that hosts an instance ... The user control class contains a DataGridView instance ... then open the main form in design mode. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: VB 2005 User Control Issue
    ... >> First of all there is a middle-tier object connected to the user control. ... >> Cor Ligthert, ... >>> It is bad design to mix up getting data from a server in an UI. ...
    (microsoft.public.dotnet.general)