1

我在 webpart main.cs 中添加了一个属性

   public override ToolPart[] GetToolParts()

        {
            ToolPart[] toolparts = new ToolPart[4];
            WebPartToolPart wptp = new WebPartToolPart();
            CustomPropertyToolPart custom = new CustomPropertyToolPart();

            CalendarToolPart datumswahl = new CalendarToolPart("Coutdown Datum Wahl");

            toolparts[0] = datumswahl;
            toolparts[1] = custom;
            toolparts[2] = wptp;

            return toolparts;
        }

然后我建立了这个类 toolpartClass.cs

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.ComponentModel;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using Microsoft.SharePoint;  
using Microsoft.SharePoint.WebControls;  
using Microsoft.SharePoint.WebPartPages;  

namespace Custom_Toolpart.toolparttest  
{    
    class CalendarToolPart : ToolPart     
{  
        public Calendar datumWahl = null;  
        private void CalendarToolPart_Init(object sender, EventArgs e)  
        {  
            datumWahl = new Calendar();  
            datumWahl.ID = "datumWahl";  

            SyncChanges();  
        }  

        public CalendarToolPart(string strTitle)
        {
            this.Title = strTitle;
            this.Init += new EventHandler(CalendarToolPart_Init);
        }

        public override void ApplyChanges()
        {
            //base.ApplyChanges();
            EnsureChildControls();  
        }

        public override void SyncChanges()
        {
            EnsureChildControls();
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            Controls.Add(datumWahl);
            this.ChildControlsCreated = true;   //?
        }
    }

我的问题是,我无法从 toolpartClass.cs 中使用/调用日历

我想要做的是,将所选日期提供给“toolpartUserControl.ascx.cs”(后面的代码),我想在其中使用日期并在 toolpart.ascx 中显示结果

在toolpartUserControl.ascx.cs中使用“正常”添加的webpart属性是没有问题的,像这里

namespace Custom_Toolpart.toolparttest  

{  

    public partial class toolparttestUserControl : UserControl  

    {  

        public toolparttest WebPart { get; set; }  

        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected override void OnPreRender(EventArgs e)
        {

            base.OnPreRender(e);

            DateTime datumAuswahl1 = DateTime.Parse(Calendar1.SelectedDate.ToString("MM") + "/" + Calendar1.SelectedDate.ToString("dd") + "/" + Calendar1.SelectedDate.ToString("yyyy"));
            DateTime datumJetzt = DateTime.Now;

            TimeSpan mySpan = new TimeSpan(-24, 0, 0);
            datumJetzt = datumJetzt.Add(mySpan);


            TimeSpan laufzeit = datumAuswahl1 - datumJetzt;
            string ausgabeLaufzeit = string.Format("{0}", laufzeit.Days);

            int i = Convert.ToInt32(ausgabeLaufzeit);
            if (i >= 2)
            {
                lbl_6.Text = "Tage";
            }
            if (i == 1)
            {
                lbl_6.Text = "Tag";
            }
            if (i == 0)
            {
                lbl_6.Text = "Tage";
                lbl_hide.Visible = true;
                lbl_1.Visible = false;
                lbl_2.Visible = false;
                lbl_3.Visible = false;
                lbl_6.Visible = false;
            }

            lbl_2.Text = ausgabeLaufzeit;


            if (this.WebPart != null && this.WebPart.CountDown_Text != null)
            {
                lbl_1.Text = this.WebPart.CountDown_Text.ToString();
            }

            if (this.WebPart != null && this.WebPart.Event_Text != null)
            {
                lbl_3.Text = this.WebPart.Event_Text.ToString();
            }

            if (this.WebPart != null && this.WebPart.Header_Text != null)
            {
                lbl_4.Text = this.WebPart.Header_Text.ToString();
            }

            if (this.WebPart != null && this.WebPart.Main_Text != null)
            {
                lbl_5.Text = this.WebPart.Main_Text.ToString();
            }

            if (this.WebPart != null && this.WebPart.Link_Edit != null)
            {
                hyplnk_1.NavigateUrl = this.WebPart.Link_Edit.ToString();
            }

            if (this.WebPart != null && this.WebPart.Ablauf_Text != null)
            {
                lbl_hide.Text = this.WebPart.Ablauf_Text.ToString();
            }
        }
    }
}

如何将所选日期发送到 toolpartUserControl.ascx.cs 类?

4

0 回答 0