1. I'm having troubles referencing nested controls.
I have a dialog, inside that dialog is an AJAXUploader, inside the LayoutTemplate of the AJAXUploader are my controls. This nesting is necessary to put the AJAXUploader save button where I want it.
I have a handle to the AJAXUploader, retrieved like this.
Code: C#
AJAXUploader fuFiles = (AJAXUploader)dlgFileEditor.ContentContainer.FindControl("fuFiles");
where fuFiles is the name of the AJAXUploader and dlgFileEditor is the name of the dialog control.
That works fine, now I need to get access to the text box's and whatnot inside the AJAXUploader, I would have thought that
Code: C#
TextBox tbxFileTitle = (TextBox)fuFiles.FindControl("tbxFileTitle");
would work, since fuFiles now points to the actual ajax uploader, but it does not.
Also, TextBox tbxFileTitle = (TextBox)dlgFileEditor.ContentContainer.FindControl("tbxFileTitle"); does not work.
neither does
TextBox tbxFileTitle = (TextBox)fuFiles.TemplateControl.FindControl("tbxFileTitle");
Any ideas.
2. I have a drop down list in the AJAXUploader LayoutTemplate that has 1,2,3 . . for values, and is set to autopostback and OnSelectedIndexChanged="ddlNumFiles_SelectedIndexChanged"
The problem is, this event doesn't get fired when the ddl is in the AJAXUploader control. The postback happens, but the associated event is "skipped". When I move the drop down list outside of the AJAXUploader, the event fires fine.
How to fix
3. When fuFiles.Rows is set greater then 1 (say to 3 for instance) the spacing is too great between each row. I am using the LayoutTemplate as you will see below and have not found a way of decreasing the spacing.
Thank you!!!
Code: HTML/ASPX
<eo:Dialog runat="server" id="dlgFileEditor"
CloseButtonUrl="/masterpages/theme_orange/Close_Simple.png"
IsModal="true" AllowResize="True"
ControlSkinID="None" Width="500px"
ShadowColor="LightGray" ShadowDepth="3"
ResizeImageUrl="00020014" HeaderHtml="File Editor"
BackShadeColor="gray" BackShadeOpacity="50" >
<HeaderStyleActive CssText="Color:#fff; font-weight:bold; padding-right: 4px; padding-left: 4px; background:url('/masterpages/Theme_Orange/TitleBar.png') repeat-x left top;"></HeaderStyleActive>
<ContentStyleActive CssClass="ControlBackground"></ContentStyleActive>
<ContentTemplate>
<eo:AJAXUploader runat="server" ID="fuFiles" AutoPostBack="true" OnFileUploaded="FileUploaded" TempFileLocation="d:\CMS_Upload_Files_Temp">
<LayoutTemplate>
<div class="ControlBar">
<div class="ControlBarLeft">
Files to Upload
<asp:DropDownList ID="ddlNumFiles" runat="server" CssClass="TitleBarControls" AutoPostBack="true" OnSelectedIndexChanged="ddlNumFiles_SelectedIndexChanged" >
<asp:ListItem Value="1" />
<asp:ListItem Value="2" />
<asp:ListItem Value="3" />
<asp:ListItem Value="4" />
<asp:ListItem Value="5" />
<asp:ListItem Value="6" />
<asp:ListItem Value="7" />
<asp:ListItem Value="8" />
<asp:ListItem Value="9" />
<asp:ListItem Value="10" />
<asp:ListItem Value="11" />
<asp:ListItem Value="12" />
<asp:ListItem Value="13" />
<asp:ListItem Value="14" />
<asp:ListItem Value="15" />
</asp:DropDownList>
</div>
<div class="ControlBarRight">
<asp:LinkButton id="UploadButton" runat="server" Text="span>" CssClass="button"></asp:LinkButton>
</div>
</div>
<asp:Table ID="tblFileEditor" BorderStyle="none" CellSpacing="0" CssClass="TableDetailsView" runat="server" EnableTheming="false">
<asp:TableRow>
<asp:TableHeaderCell>
<asp:Image ID="imgFileImage" runat="server" />
<asp:Textbox ID="tbxFileID" runat="server" Visible="false" />
File
</asp:TableHeaderCell>
<asp:TableCell>
<asp:PlaceHolder id="InputPlaceHolder" runat="server" />
<eo:ProgressBar id="ProgressBar" runat="server" ControlSkinID="None" Height="18px" BorderColor="black" BorderStyle="Solid" BorderWidth="1px" BackColor="#f4c3a3" IndicatorColor="#ec7e3b" />
<asp:PlaceHolder id="ProgressTextPlaceHolder" runat="server" />
<asp:PlaceHolder id="PostedFilesPlaceHolder" runat="server" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableHeaderCell>
Group
</asp:TableHeaderCell>
<asp:TableCell>
<asp:DropDownList ID="ddlFileEditorGroup" OnDataBound="ddlFileEditorGroup_OnDataBound" runat="server" DataSourceID="dsFileEditorGroups" DataTextField="GroupName" DataValueField="GroupID" AppendDataBoundItems="true" >
<asp:ListItem Text=" --None--" Value="" Selected="true" />
</asp:DropDownList>
<asp:SqlDataSource ID="dsFileEditorGroups" runat="server" ConnectionString="<%$ ConnectionStrings:Conn_CMS_View %>" SelectCommand="SELECT * FROM [Groups] WHERE ([SiteID] = @SiteID) ORDER BY [GroupName]">
<SelectParameters>
<asp:SessionParameter Name="SiteID" SessionField="Site" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableHeaderCell>
Title
</asp:TableHeaderCell>
<asp:TableCell>
<asp:TextBox ID="tbxFileTitle" runat="server" Width="98%" />
</asp:TableCell>
</asp:TableRow>
. . . Code Deleted
</asp:Table>
</LayoutTemplate>
</eo:AJAXUploader>
</ContentTemplate>
</eo:Dialog>
Code: C#
protected void ddlNumFiles_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlNumFiles = (DropDownList)dlgFileEditor.ContentContainer.FindControl("ddlNumFiles");
AJAXUploader fuFiles = (AJAXUploader)dlgFileEditor.ContentContainer.FindControl("fuFiles");
fuFiles.Rows = Convert.ToInt32(ddlNumFiles.SelectedValue);
}
protected void FileUploaded(object sender, EventArgs e)
{
//Get all the posted files
AJAXUploader fuFiles = (AJAXUploader)dlgFileEditor.ContentContainer.FindControl("fuFiles");
AJAXPostedFile[] files = fuFiles.PostedFiles;
foreach (AJAXPostedFile file in files)
{
FileStream fs1 = new FileStream(file.TempFileName, FileMode.Open);
byte[] imageBytes = new byte[fs1.Length];
fs1.Read(imageBytes, 0, imageBytes.Length);
fs1.Close();
fs1.Dispose();
string strExtension = GetExtension(file.ClientFileName.ToString().Trim());
TextBox tbxFileTitle = (TextBox)fuFiles.FindControl("tbxFileTitle");
. . . some code deleted
//Get proper File Title
string strFileTitle = "";
if (tbxFileTitle.Text.ToString().Trim() == "")
strFileTitle = file.ClientFileName.ToString();
else
strFileTitle = tbxFileTitle.Text.ToString().Trim();
. . . save code deleted
files = null;
fuFiles.ClearPostedFiles();
fuFiles.Dispose();
}
David L. Sargent
Developer
Washington State University