using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Bitrix.UI;
using System.IO;
using System.Collections.Generic;

using Bitrix.IBlock;
using Bitrix.Modules;
using Bitrix.Security;

public partial class bitrix_components_bitrix_photogallery_upload_templates__default_template : BXComponentTemplate<PhotogalleryUpload>
{
    protected override void OnInit(EventArgs e)
    {
        if (Results.ContainsKey("Albums"))
        {
            lbSections.Items.Clear();
            ListItemCollection albums = (ListItemCollection)Results["Albums"];
            foreach (ListItem item in albums)
            {
                lbSections.Items.Add(item);
                SelectAlbums.Items.Add(item);
            }
        }

        lbSections.SelectedValue = Component.AlbumId.ToString();
        SelectAlbums.SelectedValue = Component.AlbumId.ToString();

        base.OnInit(e);
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        Component.TrySaveImages(Component.AlbumId);
    }

    //protected override void OnPreRender(EventArgs e)
    //{
    //    //Component.TrySaveImages(int.Parse(lbSections.SelectedValue));
    //    base.OnPreRender(e);
        
        
    //}

    protected void GoToAlbum_Click(object sender, EventArgs e)
    {
        Results["AlbumId"] = int.Parse(SelectAlbums.SelectedValue);
        Response.Redirect(Component.MakeLink(Parameters.Get("UrlTemplateUpload","")));
    }
}
