在自定义控件中加入一个 public 属性,该属性返回 calendar控件中选择的当前日期。当通过该属性获取了日期之后,将 mycalendar.Visible 设为 false;

解决方案 »

  1.   

    增加一个模块级变量:
    protected Calendar1 mycalendar;
      

  2.   

    在使用自定义控件的时候要注意,你需要在test.aspx.cs文件中添加一句话,
    protected System.Web.UI.WebControls.Label Label8;
    如果你的页面上,有两个以上的控件,那么你可以看到这句话的位置何意思的。
      

  3.   

    还是不行啊。
    我在自定义控件中加入了:
        Public Property getSelectDate() As Date
            Get
                getSelectDate = CalendarSet.VisibleDate
                CalendarSet.Visible = False
            End Get
            Set(ByVal Value As Date)
                getSelectDate = Value
                CalendarSet.VisibleDate = getSelectDate
            End Set
        End Property之后在页面中使用时(Label1.Text = calendar1.getSelectDate())提示:
    getSelectDate不是System.Web.UI.UserControl的成员,
    会是什么问题呢,是我写借了吗
    (Protected WithEvents calendar1 As System.Web.UI.UserControl)
      

  4.   

    在test.aspx.vb文件中我定义如下:
      Protected WithEvents Label1 As System.Web.UI.WebControls.Label
      Protected WithEvents calendar1 As System.Web.UI.UserControl
    在用Label1.Text = Calendar1.getSelectDate()进就提示上面的借误.
      

  5.   

    Protected WithEvents calendar1 As System.Web.UI.UserControl
    后面的类名,是你在.ascx.vb中的类名。
      

  6.   

    在页面test.aspx中,显示自定义控件时并有选择某一日期时,我该如何读取所选的日期,并将自定义控件隐含掉呢?
    代码如下
    private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
    {
    TextBox1.Text=Calendar1.SelectedDate.ToString();
    Calendar1.Visible=false;
    }
      

  7.   

    楼上的a9706103(桃花岛主) 
    拜托你说清楚点好吗?
    你那代码是写到哪里的,控件是test.aspx文件上件的吗?致icyer() ,
    我在test.aspx.vb文件中定义了以下语句
    Protected WithEvents calendar1 As System.Web.UI.UserControl
    怎还读不了自定义控件中的属性项呢Calendar1.getSelectDate()?附:
    自定控件的文件名及类另都为calendar
    自定义控件在test.aspx文件中的ID为Calendar1
      

  8.   

    各位,上面是语句Protected WithEvents calendar1 As System.Web.UI.UserControl
    应该还不能将变量定义成那个自定义的控件吧,(因为该语句根本没有指定是哪一个自定义的控件),该定义过程该如何做好呢?
    (因Protected WithEvents calendar1 As System.Web.UI.UserControl.calendar是错的)
      

  9.   

    我在文件.ascx文件中加进了一个Calendar控件,以定义成一个自定义控件()。
    我是不太明白,你是要把这个控件当成你的自定义控件???还是要两个控件并存,calendar不是可以读选中的日期吗。读了以后一隐藏你要隐藏的东西可以了吧。
      

  10.   

    感谢您使用微软产品。首先,请您确认我对这个问题是否理解正确:1。 您订制了一个自己的User Control (ascx文件),并在这个UserControl中包含了一个Calendar Server Control.2. 在您的Web Page中,您要在代码中得到Calendar中的当前日期,并可以通过代码控制该UserControl显示与否。如果我没有理解错误,建议您参考下面的方法。由于对C#比较了解,所以我使用了C#,相信原理是一样的。请谅解 -:)1。 请确认您的ascx文件中声明的有对应该UserControl的类。如果您使用Code-Behind, 则在您的ascx.vb文件中,会有该类。如果您的UserControl的代码和HTML在同一个ascx文件中,您需要声明下面语句,注册类:<%@ Control className="MyUserControl" %>2。 在ascx对应的类中,声明一个public属性,用来传出当前选中的日期:public System.DateTime SelectDate
    {
    get
    {
    return this.Calendar1.SelectedDate;
    }
    }
    3。 在您的aspx文件中,不要使用<%@Register...%>,而使用下面的声明语句:<%@ Reference control="MyUserControl.ascx"%>4。 在您的aspx文件对应的类中,声明下面的变量,用来保存将要生成的UserControl对象: protected Control con;4. 在您的Page_Load事件中,加入下面的代码:con=LoadControl("MyUserControl.ascx");//"form1"是您的aspx文件中<form runat=server>的ID, 当然,您也可以把该对象放入其他container.Control frm=this.FindControl("form1");frm.Controls.Add(con);

    Label1.Text=( (MyUserControl) con).SelectDate.ToString();this.con.Visible=false;this.con.Visible=true;5.现在,您就可以像控制aspx中的Textbox对象一样,控制UserControl对象。希望对您有所帮助。-微软全球技术中心 本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
    为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
      

  11.   

    感谢感谢zgh_ms([微软] 百变金刚) !!!
    你已正确理解我的意思了,我回去好好用一下你的方法,我在自定义控件中使用calendar控件原因是:
    web server 的calendar控件不能满足我的需要,我要在calecdar中增加一些我自已的东西.
      

  12.   

    谁让你这样定义的?
    Protected WithEvents calendar1 As System.Web.UI.UserControl.calendar我是让你把后面部分替换成*.ascx中的类名。
    比如:
    Protected WithEvents calendar1 As MyUserControl