R
Ric
im new to asp.net. from what i understand, you have the aspx file
(presentation), user-control(ascx file), code-behind(vb file) and
components(compiled vb and dll files). the aspx file contains a
reference to the ascx which can contain a reference to a component.
can an aspx file contain a reference to an ascx file which contains a
reference to a code-behind file? ive tried to do this then load the
user-control via LoadControl(), but i get the following error.
Compiler Error Message: BC30002: Type 'uc1' is not defined.
Source Error:
Line 11: Dim ctlControl as Control
Line 12: ctlControl = LoadControl("usercontrol/uc1.ascx")
Line 13: Ctype(ctlControl, uc1).BackColor = "blue"
Line 14: plCB2.Controls.add(ctlcontrol)
Line 15: end sub
here is the code
ASPX file
<%@ Page Inherits="cb1" src="codeBehind/cb1.vb" Debug="true" %>
<%@ Register TagPrefix="sc" TagName="uc1" src="usercontrol/uc1.ascx"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ Import namespace="myComponents" %>
<script runat="server">
Overrides sub page_load
myBase.page_load
lblHeader.Text = "Override CB1 Message"
end sub
sub cb2_load(s as Object, e as EventArgs)
Dim ctlControl as Control
ctlControl = LoadControl("usercontrol/uc1.ascx")
Ctype(ctlControl, uc1).BackColor = "blue"
plCB2.Controls.add(ctlcontrol)
end sub
sub AddV(s as Object, e as EventArgs)
Dim myAdder as New cb1
myAdder.fV = rnd(10)
myAdder.sV = rnd(50)
lblOutput.Text = "Add V " & myAdder.AddValues()
end sub
sub myComp(s as Object, e as EventArgs)
Dim myQuote as New Quote
lblmyComp.text = myQuote.ShowQuote()
end sub
</script>
<html>
<body>
<form runat="server">
<asp:Literal Text="I love ASP. NET!?" runat="server" />
</p>
<asp:Button Text="Click Here" OnClick="Button_Click" runat="server"/>
</p>
<asp:Button Text="Load CB2" OnClick="cb2_load" runat="server"/>
</p>
<asp:Label ID="lblMessage" runat="server"/>
</p>
<asp:Label ID="lblHeader" runat="server"/>
</p>
<asplaceHolder ID="plCB2" runat="server"/>
</p>
<asp:Button Text="Add" OnClick="AddV" runat="server"/>
</p>
<asp:Label ID="lblOutput" runat="server"/>
</p>
<asp:Button Text="Add" OnClick="myComp" runat="server"/>
</p>
<asp:Label ID="lblmyComp" runat="server"/>
</form>
</body>
</html>
ASCX file
<%@ Inherits="cb2" %>
<font color="<%=BackColor%>"><b>UC1 ASCX with CB2</b></font>
CODE-BEHIND FILE
' VB Document
Imports System
Imports System.Web.UI
'Imports System.Web.UI.WebControls
Public Class cb2
Inherits UserControl
Public BackColor As String = "Red"
End Class
Also, is System.Web.UI.WebControls part of the 1.1 framework. when i
tried to compile it with System.Web.UI.WebControls i got a file not
found error.
thx
Ric
(presentation), user-control(ascx file), code-behind(vb file) and
components(compiled vb and dll files). the aspx file contains a
reference to the ascx which can contain a reference to a component.
can an aspx file contain a reference to an ascx file which contains a
reference to a code-behind file? ive tried to do this then load the
user-control via LoadControl(), but i get the following error.
Compiler Error Message: BC30002: Type 'uc1' is not defined.
Source Error:
Line 11: Dim ctlControl as Control
Line 12: ctlControl = LoadControl("usercontrol/uc1.ascx")
Line 13: Ctype(ctlControl, uc1).BackColor = "blue"
Line 14: plCB2.Controls.add(ctlcontrol)
Line 15: end sub
here is the code
ASPX file
<%@ Page Inherits="cb1" src="codeBehind/cb1.vb" Debug="true" %>
<%@ Register TagPrefix="sc" TagName="uc1" src="usercontrol/uc1.ascx"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ Import namespace="myComponents" %>
<script runat="server">
Overrides sub page_load
myBase.page_load
lblHeader.Text = "Override CB1 Message"
end sub
sub cb2_load(s as Object, e as EventArgs)
Dim ctlControl as Control
ctlControl = LoadControl("usercontrol/uc1.ascx")
Ctype(ctlControl, uc1).BackColor = "blue"
plCB2.Controls.add(ctlcontrol)
end sub
sub AddV(s as Object, e as EventArgs)
Dim myAdder as New cb1
myAdder.fV = rnd(10)
myAdder.sV = rnd(50)
lblOutput.Text = "Add V " & myAdder.AddValues()
end sub
sub myComp(s as Object, e as EventArgs)
Dim myQuote as New Quote
lblmyComp.text = myQuote.ShowQuote()
end sub
</script>
<html>
<body>
<form runat="server">
<asp:Literal Text="I love ASP. NET!?" runat="server" />
</p>
<asp:Button Text="Click Here" OnClick="Button_Click" runat="server"/>
</p>
<asp:Button Text="Load CB2" OnClick="cb2_load" runat="server"/>
</p>
<asp:Label ID="lblMessage" runat="server"/>
</p>
<asp:Label ID="lblHeader" runat="server"/>
</p>
<asplaceHolder ID="plCB2" runat="server"/>
</p>
<asp:Button Text="Add" OnClick="AddV" runat="server"/>
</p>
<asp:Label ID="lblOutput" runat="server"/>
</p>
<asp:Button Text="Add" OnClick="myComp" runat="server"/>
</p>
<asp:Label ID="lblmyComp" runat="server"/>
</form>
</body>
</html>
ASCX file
<%@ Inherits="cb2" %>
<font color="<%=BackColor%>"><b>UC1 ASCX with CB2</b></font>
CODE-BEHIND FILE
' VB Document
Imports System
Imports System.Web.UI
'Imports System.Web.UI.WebControls
Public Class cb2
Inherits UserControl
Public BackColor As String = "Red"
End Class
Also, is System.Web.UI.WebControls part of the 1.1 framework. when i
tried to compile it with System.Web.UI.WebControls i got a file not
found error.
thx
Ric