date.ascx:<%@ Control Language="vb" AutoEventWireup="false" Codebehind="date.ascx.vb" Inherits="aspnetlabs._date" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> data.ascx.vb: Public Class _date Inherits System.Web.UI.UserControl#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 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 End Sub Public Property MyText() As String Get If ViewState("MyDate") Is Nothing Then Return "" End If Return CType(ViewState("MyDate"), String) End Get Set(ByVal Value As String) ViewState("MyDate") = Value End Set End Property End Classtestdata.aspx: <%@ Register TagPrefix="uc1" TagName="date" Src="date.ascx" %> <uc1:date id="Date1" runat="server"></uc1:date>code behind: Dim Date1 as _dateDate1.MyText = "123"
<hPglt:Tdate id="pltDate" runat="server" />
现在我想在后台CS程序中给pltDate中的一个变量赋值,则在CS程序中如何声明形用用户控件呢?
data.ascx.vb:
Public Class _date
Inherits System.Web.UI.UserControl#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 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
End Sub Public Property MyText() As String
Get
If ViewState("MyDate") Is Nothing Then
Return ""
End If Return CType(ViewState("MyDate"), String)
End Get
Set(ByVal Value As String)
ViewState("MyDate") = Value
End Set
End Property
End Classtestdata.aspx:
<%@ Register TagPrefix="uc1" TagName="date" Src="date.ascx" %>
<uc1:date id="Date1" runat="server"></uc1:date>code behind:
Dim Date1 as _dateDate1.MyText = "123"
date.ascx:
<%@ Control Language="C#" ClassName="Test"%>
<script runat="server">
public DateTime dtmTdate;
void Page_Load()
{
test.Text=dtmTdate.ToString();
}
</script>
<asp:Panel id="panDate" runat="server" Height="27px" Width="283px">
<asp:Label ID="test" runat="server" />
</asp:Panel>-------------------------------------------------
test.aspx:
<%@ Register TagPrefix="hPglt" TagName="Tdate" Src="../inc/date.ascx" %>
... ... ... ...
<hPglt:Tdate id="pltDate" runat="server" />
... ... ... ...-------------------------------------------------
test.cs
... ... ...
protected hPglt.Tdate pltDate;
... ... ...总是报"找不到类型或命名空间名称“???”(是否缺少 using 指令或程序集引用?)"请大家再次关注,谢了,如果分不够,可以分贴给分,只要能解决问题!
date.ascx
.....date.ascx.cs:class YourDateControl : User Control
{
public DateTime YourDate {get {.....} set {...}}然后在你的ASPX页里,
<hPglt:Tdate id="pltDate" runat="server" />操作你用户控件的CODE BEHIND类的对象的属性
protected YourDateControl pltDate;
...
pltDate.YourDate = ....;
date.ascx:
<%@ Control Language="C#" Inherits="inc_date" src="/inc/date.cs"%>
<asp:Panel id="panDate" runat="server" Height="27px" Width="283px">
<asp:Label ID="test" runat="server" />
</asp:Panel>---------------------------------------
date.cs:
public class inc_date:UserControl
{
public DateTime dtmTdate
{
get
{
return (dtmTdate);
}
set
{
dtmTdate=value;
}
}
... ... ...
}-------------------------------------------------
test.aspx:
<%@ Register TagPrefix="hPglt" TagName="Tdate" Src="../inc/date.ascx" %>
... ... ... ...
<hPglt:Tdate id="pltDate" runat="server" />
... ... ... ...-------------------------------------------------
test.cs
... ... ...
protected inc_date pltDate;
... ... ...
故障依旧,恳请高手支招,多谢了! :O :O :O
<%@ Register TagPrefix="uc1" TagName="WebDateCon"Src="../userocx/WebDateCon.ascx" %>
加入using 你的命名空间;
加入protected 你的命名空间.你的控件名 id;
比如我的:项目名AE,用户控件在lib目录下,用户控件的类名是page
那么我在需要调用这个用户控件的*.aspx.cs中需要这样申明:
protected AE.lib.page Page1;