Umbraco usercontrol:在usercontrol本身中获取usercontrol.property.Id?

时间:2013-07-06 15:51:27

标签: asp.net properties user-controls umbraco

我在umbraco用户控件上遇到了一些麻烦.. 我正在尝试开发一个照片库..我有一个带有mediapicker的用户控件,并且在保存时我想在拾取的文件夹中生成所有媒体文件的缩略图。到目前为止一直很好..

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

'PhotoGalleryStorageFolder / {DocumentID} / {UsercontrolPropertyId}'

检索文档ID很简单:

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

问题是我不知道别名,我不想在我的usercontrol中对其进行硬编码,因为可能有更多的实例..

代码:

    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提前!

2 个答案:

答案 0 :(得分: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())
    {

答案 1 :(得分:0)

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