2013-07-06 33 views
1

我用umbraco用戶控件遇到了一些麻煩.. 我正在嘗試開發一個照片庫..我有一個用戶控件,上面有一個mediapicker,並保存我想生成所有的mediafiles的縮略圖挑選文件夾。到目前爲止好..Umbraco usercontrol:獲取usercontrol本身內的usercontrol.property.Id?

這可能是1號文件中包含的圖片庫屬性的不止一個,所以要確定用於存儲縮略圖我必須做這樣的事情的路徑:

「PhotoGalleryStorageFolder/{DocumentID}/{UsercontrolPropertyId}」

檢索文檔ID很容易:

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

的問題是,我不知道的別名,我不想硬編碼在我的用戶,因爲這樣可能更多i牛逼..

代碼:

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

回答

0

我最後增加一個額外的文本框(僅管理員可見)到該用戶控件,所以開發人員現在可以定義一個子文件夾中圖片集錦的每個實例。無論如何Thnx對所有的幫助。

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()) 
    { 
+0

Thnx爲您的迴應!但是我需要usercontrol中的umbraco propertyId。這隻會循環通過usercontrol中的所有控件。 –