声明一个模块级变量: Protected WithEvents UserCtrl1 As UserControl1 'UserControl1是你的用户控件的类名。
我的用户控件写在properties.ascx,其properties.ascx.vb内第一句是 Public MustInherit Class properties properties是不是就是我的控件类名。可我在WebForm4.aspx.vb里声明了 Protected WithEvents UserCtrl1 As properties提示我“Color不是WebApplication1.properties的成员”!这是为什么???谢谢!!!
在properties.ascx里定义的。<%@ Control Language="vb" AutoEventWireup="false" Codebehind="properties.ascx.vb" Inherits="WebApplication1.properties" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> <script language="VB" runat="server"> Public Color As String ="black" Public Text As String = "This is a user control...really!" </script> <P> <font color="<%= Color %>"> <%=text%> </font> </P>
你要转换一下才可以用。 dim oUCtrl as 控件所属的class =ctype(UserCtrl1 ,控件所属的class )以后你就可以用oUCtrl了。
我的意思是:我在*.aspx里有 <form method="post" runat="server"> Qty:<asp:TextBox ID ="Qty" Runat="server"/> </form> 如果我要在*.aspx.vb里引用要先定义 Protected qty As TextBox那如果我要引用一个用户控件该如何写呢? 用户控件如下: <%@ Control Language="vb" AutoEventWireup="false" Codebehind="properties.ascx.vb" Inherits="WebApplication1.properties" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %><script language="VB" runat="server"> Public Color As String ="black" Public Text As String = "This is a user control...really!" </script> <P> <font color="<%= Color %>"> <%=text%> </font> </P>
在什么地方声明呢?
Protected WithEvents UserCtrl1 As UserControl1
'UserControl1是你的用户控件的类名。
Public MustInherit Class properties
properties是不是就是我的控件类名。可我在WebForm4.aspx.vb里声明了
Protected WithEvents UserCtrl1 As properties提示我“Color不是WebApplication1.properties的成员”!这是为什么???谢谢!!!
UserControl1 uc=(UserControl1)FindControl("uc");
uc.Color = Color.Green;
<script language="VB" runat="server">
Public Color As String ="black"
Public Text As String = "This is a user control...really!"
</script>
<P>
<font color="<%= Color %>">
<%=text%>
</font>
</P>
dim oUCtrl as 控件所属的class =ctype(UserCtrl1 ,控件所属的class )以后你就可以用oUCtrl了。
<form method="post" runat="server">
Qty:<asp:TextBox ID ="Qty" Runat="server"/>
</form>
如果我要在*.aspx.vb里引用要先定义
Protected qty As TextBox那如果我要引用一个用户控件该如何写呢?
用户控件如下:
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="properties.ascx.vb" Inherits="WebApplication1.properties" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %><script language="VB" runat="server">
Public Color As String ="black"
Public Text As String = "This is a user control...really!"
</script>
<P>
<font color="<%= Color %>">
<%=text%>
</font>
</P>