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;
        }
    }

これに関するヘルプは素晴らしいでしょう..前もってThnx!

4

2 に答える 2

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 に答える