1

我在使用 umbraco 用户控件时遇到了一些问题。我正在尝试开发照片库。我有一个带有媒体选择器的用户控件,在保存时我想生成所选文件夹中所有媒体文件的缩略图。到目前为止,一切都很好..

1 个文档可能包含多个照片库属性,因此要确定存储缩略图的路径,我必须执行以下操作:

'PhotoGalleryStorageFolder/{DocumentID}/{UsercontrolPropertyId}'

检索文档 ID 很简单:

_currentNodeId = int.Parse(Request.QueryString["id"]);

问题是我不知道别名,我不想在我的用户控件中硬编码它,因为它可能有更多实例..

代码:

    private Int32 _currentNodeId = -1;
    private Int32 _currentPhotoGalleryId = -1;
    private String _value = ""; // Holds MediaPickerValue;

    protected void Page_Load(object sender, EventArgs e)
    {
        initialize();
    }

    #region Initialize
    private void initialize()
    {
        _currentNodeId = int.Parse(Request.QueryString["id"]);

        /////// PROBLEM \\\\\\\\\
        _currentPhotoGalleryId = -1; // How to retrieve this?!?!
        \\\\\\\ PROBLEM /////////

        Document d = new Document(_currentNodeId);

        if (!Page.IsPostBack)
        {
            this.setMediaPickerValue(_value);
            this.setPrevMediaPickerValue(_value);
        }
        else
            _value = this.getMediaPickerValue();

        Response.Write("_currentNodeId: " + _currentNodeId.ToString() + "<br />");
        Response.Write("_value: " + _value + "<br />");
    }

    void Document_AfterSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
    {

    }

    #endregion

    #region MediaPickerValue
    private String getMediaPickerValue()
    {
        return mediaPicker.Value;
    }

    private void setMediaPickerValue(String value)
    {
        mediaPicker.Value = value;
    }

    private String getPrevMediaPickerValue()
    {
        return prevMediaPickerValue.Value;
    }

    private void setPrevMediaPickerValue(String value)
    {
        prevMediaPickerValue.Value = value;
    }
    #endregion

    #region OnSave
    private void onSave()
    {
        String currentValue = this.getMediaPickerValue();
        String prevValue = this.getPrevMediaPickerValue();

        if (currentValue != prevValue) HttpContext.Current.Response.Write("Hergenereer thumbs.<br />");
        else HttpContext.Current.Response.Write("Thumbs hoeven niet opnieuw te worden gegenereerd.<br />");

        this.setPrevMediaPickerValue(currentValue);
    }
    #endregion

    public object value
    {
        get
        {
            onSave();
            return this.getMediaPickerValue();
        }
        set
        {
            Response.Write("Set triggered<br />");
            String val = string.IsNullOrEmpty(value.ToString())  || value == null ? "" : value.ToString();
            _value = val;
        }
    }

对此的任何帮助都会很棒..提前谢谢!

4

2 回答 2

0

我最终向用户控件添加了一个额外的文本框(仅对管理员可见),因此开发人员现在可以为 PhotoGallery 的每个实例定义一个子文件夹。无论如何,谢谢所有的帮助。

于 2013-07-09T16:54:44.347 回答
0

在页面或用户控件中运行圆形控件非常简单(http://msdn.microsoft.com/en-us/library/20zys56y(v=vs.90).aspx

就像获取对象的属性一样 (( http://msdn.microsoft.com/en-us/library/aky14axb.aspx ))

EG 运行任何文本框的属性:

ControlCollection controls = this.Controls;
foreach(Control control in controls)
{
  if (control.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
  {
    // if this is the control you are interested in you can loop round its properties
    // something like 
    foreach (var prop in control.GetProperties())
    {
于 2013-07-08T08:53:15.223 回答