declare them public or expose them as properties

解决方案 »

  1.   

    <%@ Register TagPrefix="hPglt" TagName="Tdate" Src="../inc/date.ascx" %>
    <hPglt:Tdate id="pltDate" runat="server" />
    现在我想在后台CS程序中给pltDate中的一个变量赋值,则在CS程序中如何声明形用用户控件呢?
      

  2.   

    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"
      

  3.   

    仍然搞不定,关键代码如下:---------------------------------------
    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 指令或程序集引用?)"请大家再次关注,谢了,如果分不够,可以分贴给分,只要能解决问题!
      

  4.   

    再说一遍,在你的用户控件里用CODE BEHIND类,在其中建立属性,
    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 = ....;
      

  5.   

    ---------------------------------------
    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
      

  6.   

    客户端
    <%@ Register TagPrefix="uc1" TagName="WebDateCon"Src="../userocx/WebDateCon.ascx" %>
    加入using 你的命名空间;
    加入protected 你的命名空间.你的控件名  id;
      

  7.   

    看一下你的用户控件所在的命名空间是什么
    比如我的:项目名AE,用户控件在lib目录下,用户控件的类名是page
    那么我在需要调用这个用户控件的*.aspx.cs中需要这样申明:
    protected AE.lib.page Page1;