Umbraco usercontrol:在用户控件本身中获取usercontrol.propertiesId



我在使用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;
        }
    }

在这方面有任何帮助都将是非常好的。。提前Thnx!

在页面或用户控件中运行循环控件很简单(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())
    {

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

最新更新