|
Rank: Member Groups: Member
Joined: 9/14/2007 Posts: 21
|
Good morning, we have recently purchased all of the controls and I am trying to implement Async File Upload and uploading to a database. All of my controls are in a Microsoft Ajax Update Panel and the upload controls are in an Ajax Control Toolkit Modal Dialog box control. I can upload the first file fine, the second fille I try to upload will cause the first file to be rewritten to the database. It seems that PostedFiles is not being cleared out between async uploads even though I am doing everything I can find to clear it. My code is posted below.
Code: C#
protected void FileUploaded(object sender, EventArgs e)
{
//Get all the posted files
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());
//Get proper File Title
string strFileTitle = "";
if (tbxFileTitle.Text.ToString().Trim() == "")
strFileTitle = file.ClientFileName.ToString();
else
strFileTitle = tbxFileTitle.Text.ToString().Trim();
SqlConnection con = new SqlConnection(editConnectionString);
string strSQL = "";
strSQL = "INSERT INTO [Files](";
strSQL += "[Title]";
strSQL += ",[Subject]";
strSQL += ",[Description]";
strSQL += ",[Keywords]";
strSQL += ",[GroupID]";
strSQL += ",[FileTypeID]";
strSQL += ",[FileName]";
strSQL += ",[BinaryFile]";
strSQL += ",[DateAdded]";
strSQL += ",[isActive]";
strSQL += ",[SiteID]";
strSQL += ") VALUES(";
strSQL += "@Title ";
strSQL += ",@Subject";
strSQL += ",@Description";
strSQL += ",@Keywords";
strSQL += ",@GroupID";
strSQL += ",@FileTypeID";
strSQL += ",@FileName";
strSQL += ",@BinaryFile";
strSQL += ",@DateAdded";
strSQL += ",@isActive";
strSQL += ",@SiteID";
strSQL += ")";
SqlCommand cmdInsert = new SqlCommand(strSQL, con);
cmdInsert.Parameters.AddWithValue("@Title", strFileTitle);
cmdInsert.Parameters.AddWithValue("@Subject", tbxFileSubject.Text);
cmdInsert.Parameters.AddWithValue("@Description", tbxFileDescription.Text);
cmdInsert.Parameters.AddWithValue("@Keywords", tbxFileKeywords.Text);
cmdInsert.Parameters.AddWithValue("@GroupID", ddlFileEditorGroup.SelectedValue);
cmdInsert.Parameters.AddWithValue("@FileTypeID", strExtension);
cmdInsert.Parameters.AddWithValue("@FileName", file.ClientFileName.ToString().Trim());
cmdInsert.Parameters.AddWithValue("@BinaryFile", imageBytes);
cmdInsert.Parameters.AddWithValue("@DateAdded", DateTime.Today.ToShortDateString());
cmdInsert.Parameters.AddWithValue("@isActive", cboFileIsActive.Checked);
cmdInsert.Parameters.AddWithValue("@SiteID", intSiteID);
try
{
con.Open();
cmdInsert.ExecuteNonQuery();
if (con.State == ConnectionState.Open)
{ con.Dispose(); }
}
catch (Exception ex)
{
PF.Email.ErrorEmail("Error on INSERT for CMS Files", "CMS Files", "", ex);
}
}
files = null;
fuFiles.ClearPostedFiles();
//fuFiles.Dispose(); // tried with and without, no difference.
//fuFiles.Visible = false;
HiddenButtonThatDoesNothingFileEditor.Visible = false;
pnlFileEditor.Visible = false;
pnlEditors.Visible = true; // all of these are hidden to speed up code rendering
dsFiles_Selecting(null, null);
}
David L. Sargent Developer Washington State University
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi Sarge,
Your code looks correct. We have just tried to the same scenario and it appears to work fine. If you enable the posted file list section of the uploader (enabled by default), do you see the list is cleared after you postback?
Thanks
|
|
Rank: Member Groups: Member
Joined: 9/14/2007 Posts: 21
|
I didn't have the PostedFilesPlaceHolder on as I am using the templating functionality. I put in a PostedFilesPlaceHolder only to find it disappears immediately. I disabled the ModalPopupExtender (part of the Ajax Control Tookit) and with that turned off, it no longer re-saves the same file. There must be a bug between the ajax control tookit's modal popup http://www.asp.net/AJAX/Control-Toolkit/Live/ModalPopup/ModalPopup.aspxand the Async upload. Any ideas on how I can fix this? Posting my controls below
Code: HTML/ASPX
<asp:Panel runat="server" Width="500px" ID="pnlFileEditor" CssClass="ModalControl" Style="display: none" Visible="false">
<asp:Panel ID="pnlFileEditorTitle" runat="server" Style="cursor: move;">
<div class="TitleBar">
<div class="TitleBarLeft">
File Editor
</div>
<div class="TitleBarRight">
<asp:LinkButton ID="lnkbDoneEditingFile" OnClick="CloseFileEditor" runat="server" CausesValidation="false" Text=" " CssClass="CloseButton" />
</div>
</div>
</asp:Panel>
<eo:AJAXUploader runat="server" ID="fuFiles" AutoPostBack="true" OnFileUploaded="FileUploaded" TempFileLocation="d:\CMS_Upload_Files_Temp">
<LayoutTemplate>
<div class="ControlBar">
<div class="ControlBarLeft">
</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 Width="80px">
<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:Table>
</LayoutTemplate>
</eo:AJAXUploader>
<asp:Table ID="tblFileEditor2" BorderStyle="none" CellSpacing="0" CssClass="TableDetailsView" runat="server" EnableTheming="false">
<asp:TableRow>
<asp:TableHeaderCell Width="80px">
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>
<asp:TableRow>
<asp:TableHeaderCell>
Subject
</asp:TableHeaderCell>
<asp:TableCell>
<asp:TextBox ID="tbxFileSubject" runat="server" Width="98%" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableHeaderCell>
Description
</asp:TableHeaderCell>
<asp:TableCell>
<asp:TextBox ID="tbxFileDescription" Rows="3" TextMode="multiline" runat="server" Width="98%" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableHeaderCell>
Keywords
</asp:TableHeaderCell>
<asp:TableCell>
<asp:TextBox ID="tbxFileKeywords" Rows="2" TextMode="multiline" runat="server" Width="98%" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableHeaderCell>
Active
</asp:TableHeaderCell>
<asp:TableCell>
<asp:CheckBox ID="cboFileIsActive" runat="server" Checked="true" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:Panel>
<asp:Button ID="HiddenButtonThatDoesNothingFileEditor" runat="server" Text="" Style="display: none" Visible="false" />
<act:ModalPopupExtender runat="server"
ID="mpeFileEditor" TargetControlID="HiddenButtonThatDoesNothingFileEditor"
PopupControlID="pnlFileEditor" PopupDragHandleControlID="pnlFileEditorTitle"
BackgroundCssClass="modalBackground" DropShadow="true" Y="100" Enabled="false" />
David L. Sargent Developer Washington State University
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi,
You can try to use our dialog control instead of ModalPopup. It should offer all the feature that ModalPopup offers. The way our Dialog works is different than ModalPopup. It is not a "extender", but rather a "container". So its much less intrusive than ModalPopup.
Thanks
|
|
Rank: Member Groups: Member
Joined: 9/14/2007 Posts: 21
|
Well OK then. :) So, I'm trying to convert this code to use your dialog control, only I can find a way to show and hide the dialog in C#, am I missing something. I know you normally assign a button, and that would work for "new File" But in the event of someone clicking on a row in a grid view, I normally have Grid Views OnSelectedIndexChanged event open the modal dialog via a Dialog.Show() I do not find an equivalent command in your control. Ideas?
David L. Sargent Developer Washington State University
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi Sarge,
Set the Dialog's InitialState to "Visible" or "Hidden" to show/hide the dialog on the server side.
Thanks
|
|
Rank: Member Groups: Member
Joined: 9/14/2007 Posts: 21
|
OK, that works, but now I'm having trouble getting at the controls in the ContentTemplate of the eo:Dialog Normally, in a templated control I would do something like
Code: C#
AJAXUploader fuFiles1 = (AJAXUploader)dlgFileEditor.FindControl("fuFiles");
Where fuFiles is the AjaxUploader control inside the content template. This is not working. I'm getting a System.NullReferenceException Code below.
Code: HTML/ASPX
<eo:Dialog runat="server" id="dlgFileEditor" IsModal="true" CloseButtonUrl="00070101"
AllowResize="True" ControlSkinID="None" Width="500px"
ShadowColor="LightGray" ShadowDepth="3"
HeaderHtml="File Editor" ResizeImageUrl="00020014" CssClass="ModalControl">
<HeaderStyleActive CssText="padding-right: 4px; padding-left: 4px; font-size: 11px; background-image: url(00070104); padding-bottom: 3px; padding-top: 3px; font-family: tahoma"></HeaderStyleActive>
<ContentStyleActive CssText="border-top: #335c88 1px solid; background-color: #e5f1fd"></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 Width="80px">
<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:Table>
</LayoutTemplate>
</eo:AJAXUploader>
<asp:Table ID="tblFileEditor2" BorderStyle="none" CellSpacing="0" CssClass="TableDetailsView" runat="server" EnableTheming="false">
<asp:TableRow>
<asp:TableHeaderCell Width="80px">
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>
<asp:TableRow>
<asp:TableHeaderCell>
Subject
</asp:TableHeaderCell>
<asp:TableCell>
<asp:TextBox ID="tbxFileSubject" runat="server" Width="98%" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableHeaderCell>
Description
</asp:TableHeaderCell>
<asp:TableCell>
<asp:TextBox ID="tbxFileDescription" Rows="3" TextMode="multiline" runat="server" Width="98%" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableHeaderCell>
Keywords
</asp:TableHeaderCell>
<asp:TableCell>
<asp:TextBox ID="tbxFileKeywords" Rows="2" TextMode="multiline" runat="server" Width="98%" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableHeaderCell>
Active
</asp:TableHeaderCell>
<asp:TableCell>
<asp:CheckBox ID="cboFileIsActive" runat="server" Checked="true" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ContentTemplate>
</eo:Dialog>
Code: C#
protected void FileUploaded(object sender, EventArgs e)
{
//Get all the posted files
AJAXUploader fuFiles1 = (AJAXUploader)dlgFileEditor.FindControl("fuFiles");
AJAXPostedFile[] files = fuFiles1.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)dlgFileEditor.FindControl("tbxFileTitle");
TextBox tbxFileSubject = (TextBox)dlgFileEditor.FindControl("tbxFileSubject");
TextBox tbxFileDescription = (TextBox)dlgFileEditor.FindControl("tbxFileDescription");
TextBox tbxFileKeywords = (TextBox)dlgFileEditor.FindControl("tbxFileKeywords");
DropDownList ddlFileEditorGroup = (DropDownList)dlgFileEditor.FindControl("ddlFileEditorGroup");
CheckBox cboFileIsActive = (CheckBox)dlgFileEditor.FindControl("cboFileIsActive");
//Get proper File Title
string strFileTitle = "";
if (tbxFileTitle.Text.ToString().Trim() == "")
strFileTitle = file.ClientFileName.ToString();
else
strFileTitle = tbxFileTitle.Text.ToString().Trim();
SqlConnection con = new SqlConnection(editConnectionString);
string strSQL = "";
strSQL = "INSERT INTO [Files](";
strSQL += "[Title]";
strSQL += ",[Subject]";
strSQL += ",[Description]";
strSQL += ",[Keywords]";
strSQL += ",[GroupID]";
strSQL += ",[FileTypeID]";
strSQL += ",[FileName]";
strSQL += ",[BinaryFile]";
//strSQL += ",[DateUpdated]";
//strSQL += ",[DateCreated]";
strSQL += ",[DateAdded]";
strSQL += ",[isActive]";
strSQL += ",[SiteID]";
strSQL += ") VALUES(";
strSQL += "@Title ";
strSQL += ",@Subject";
strSQL += ",@Description";
strSQL += ",@Keywords";
strSQL += ",@GroupID";
strSQL += ",@FileTypeID";
strSQL += ",@FileName";
strSQL += ",@BinaryFile";
//strSQL += ",@DateUpdated";
//strSQL += ",@DateCreated";
strSQL += ",@DateAdded";
strSQL += ",@isActive";
strSQL += ",@SiteID";
strSQL += ")";
SqlCommand cmdInsert = new SqlCommand(strSQL, con);
cmdInsert.Parameters.AddWithValue("@Title", strFileTitle);
cmdInsert.Parameters.AddWithValue("@Subject", tbxFileSubject.Text);
cmdInsert.Parameters.AddWithValue("@Description", tbxFileDescription.Text);
cmdInsert.Parameters.AddWithValue("@Keywords", tbxFileKeywords.Text);
cmdInsert.Parameters.AddWithValue("@GroupID", ddlFileEditorGroup.SelectedValue);
cmdInsert.Parameters.AddWithValue("@FileTypeID", strExtension);
cmdInsert.Parameters.AddWithValue("@FileName", file.ClientFileName.ToString().Trim());
cmdInsert.Parameters.AddWithValue("@BinaryFile", imageBytes);
//cmdInsert.Parameters.AddWithValue("@DateUpdated", null);
//cmdInsert.Parameters.AddWithValue("@DateCreated", null);
cmdInsert.Parameters.AddWithValue("@DateAdded", DateTime.Today.ToShortDateString());
cmdInsert.Parameters.AddWithValue("@isActive", cboFileIsActive.Checked);
cmdInsert.Parameters.AddWithValue("@SiteID", intSiteID);
try
{
con.Open();
cmdInsert.ExecuteNonQuery();
if (con.State == ConnectionState.Open)
{ con.Dispose(); }
}
catch (Exception ex)
{
PF.Email.ErrorEmail("Error on INSERT for CMS Files", "CMS Files", "", ex);
}
}
files = null;
fuFiles1.ClearPostedFiles();
fuFiles1.Dispose();
pnlEditors.Visible = true; // all of these are hidden to speed up code rendering
dsFiles_Selecting(null, null);
}
David L. Sargent Developer Washington State University
|
|
Rank: Member Groups: Member
Joined: 9/14/2007 Posts: 21
|
Addendum. The Dialog seems to be forcing a full postback somehow, even though it is inside of an update panel. This shouldn't be happening. Example, there is a dropdownlist inside the Dialog, it is set to Autopostpack = true. When an item selects, the page does a full postback.
Any idea how to make this do a partial postback as it was before I put it in a dialog control?
David L. Sargent Developer Washington State University
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi Sarge,
As for getting child control, you will need to do Dialog1.ContentContainer.FindControl instead of Dialog1.FindControl.
As for the full postback, I just ran the following test and it works fine: 1. Put an UpdatePanel in the page; 2. Put a dialog inside the UpdatePanel's <ContentTemplate>; 3. Put a DropDownList into the dialog's <ContentTemplate> and set the DropDownList's AutoPostBack to true;
I ran the page and it does a partial update instead of a full update as expected. Can you try the same and see if it works on your side?
Thanks
|
|
Rank: Member Groups: Member
Joined: 9/14/2007 Posts: 21
|
Wow, OK, that took a while to figure out. No idea why it's doing it, but I tracked it down to WHAT is causing it. This took a LONG road of ellemination. First I created a new page on our Intranet, put a dialog in there with the drop down, all inside in Update Panel. This still caused it to do a full post back as before. This told me it was something in my Masterpages. So I started turnign off the suspects (DHTML / Javascript menu, etc) All still caused full postback. Finally narrowed it down to my main CSS file (WHAT?) Ype, it was the CSS file. Took that out, partial postback, put it back, full. Eventually narrowed it down to one line in the CSS file.
Code: CSS
.wrapper
{
position:relative;
}
Where .wrapper is the main div around all content in the Intranet., example
Code: HTML/ASPX
<div class="wrapper">
<form id="frmMain" runat="server">
<div id="menuArea">
<asp:Literal ID="ltrlMenu" runat="server"></asp:Literal>
</div>
<div id="docarea">
<asp:Literal ID="errorOutput" runat="server" Visible="false"></asp:Literal>
<asp:contentplaceholder id="cpMain" runat="server">
</asp:contentplaceholder>
</div>
</form>
<div class="push"></div>
</div>
To be honest, I'm not even sure why I have position:relative in there, took it out and everything seems to be working fine, partial postbacks and all. Still, you guys should really look into why it does this. Very odd.
David L. Sargent Developer Washington State University
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Ah....that explains. Thank you very much for your researching, it does make sense now. :) The root causes is when the dialog sees a parent element with "position:relative;", it moves its contents outside of the normal page flow. It is necessary for the dialog to do so, because "position:relative;" defines a new positioning space, specifically, a new z-Order space. Consider the following HTML code:
Code: HTML/ASPX
<div style="z-Index:2>A</div>
<div style="position:relative;z-Index:1">
<div style="z-Index:1000">B</div>
</div>
B will always be placed below A because B's parent element has a z-Index "1", which is lower than A's z-Index "2". The "position:relative" at here practically made B's z-Index as "1.1000", instead of "1000". If B were the dialog, it's obvious that there is no way to place the dialog on top of other page contents except to move B outside of its parent node. Usually this does not cause any problem. However, in your specific situation, where the UpdatePanel verifies if the trigger element is inside its boundary, it determines the trigger is outside due the element has actually been moved outside of its boundary. One more case to add into our knowledge base. Thank you very much for your contribution. :)
|
|
Rank: Member Groups: Member
Joined: 9/14/2007 Posts: 21
|
Hey, first I want to say, thank you for all of your help, you guys have really been responsive and quick to answer, I appreciate that! I've got most of it working but have a couple more questions. 1. I'm having more troubles referencing nested controls. I have a dialog, inside that dialog is a Ajax Uploader, inside the content template of the ajax uploader are my controls. This nesting is necessary to put my save button where I want it. I have a handle to the ajax uploader, 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 Ajax uploader, I would have though 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. Any ideas. 2. I have a drop down list in the Ajax Upload template that has 1,2,3 . . for values, is set to autopostback and OnSelectedIndexChanged="ddlNumFiles_SelectedIndexChanged" The problem is, this event doesn't get fired when the ddl is in ajax uploader 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 content template as you will see below and have not found a way of decreasing the spacing. Thanks 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>
<asp:TableRow>
<asp:TableHeaderCell>
Subject
</asp:TableHeaderCell>
<asp:TableCell>
<asp:TextBox ID="tbxFileSubject" runat="server" Width="98%" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableHeaderCell>
Description
</asp:TableHeaderCell>
<asp:TableCell>
<asp:TextBox ID="tbxFileDescription" Rows="3" TextMode="multiline" runat="server" Width="98%" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableHeaderCell>
Keywords
</asp:TableHeaderCell>
<asp:TableCell>
<asp:TextBox ID="tbxFileKeywords" Rows="2" TextMode="multiline" runat="server" Width="98%" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableHeaderCell>
Active
</asp:TableHeaderCell>
<asp:TableCell>
<asp:CheckBox ID="cboFileIsActive" runat="server" Checked="true" />
</asp:TableCell>
</asp:TableRow>
</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");
TextBox tbxFileSubject = (TextBox)fuFiles.FindControl("tbxFileSubject");
TextBox tbxFileDescription = (TextBox)fuFiles.FindControl("tbxFileDescription");
TextBox tbxFileKeywords = (TextBox)fuFiles.FindControl("tbxFileKeywords");
DropDownList ddlFileEditorGroup = (DropDownList)fuFiles.FindControl("ddlFileEditorGroup");
CheckBox cboFileIsActive = (CheckBox)fuFiles.FindControl("cboFileIsActive");
//Get proper File Title
string strFileTitle = "";
if (tbxFileTitle.Text.ToString().Trim() == "")
strFileTitle = file.ClientFileName.ToString();
else
strFileTitle = tbxFileTitle.Text.ToString().Trim();
SqlConnection con = new SqlConnection(editConnectionString);
string strSQL = "";
strSQL = "INSERT INTO [Files](";
strSQL += "[Title]";
strSQL += ",[Subject]";
strSQL += ",[Description]";
strSQL += ",[Keywords]";
strSQL += ",[GroupID]";
strSQL += ",[FileTypeID]";
strSQL += ",[FileName]";
strSQL += ",[BinaryFile]";
//strSQL += ",[DateUpdated]";
//strSQL += ",[DateCreated]";
strSQL += ",[DateAdded]";
strSQL += ",[isActive]";
strSQL += ",[SiteID]";
strSQL += ") VALUES(";
strSQL += "@Title ";
strSQL += ",@Subject";
strSQL += ",@Description";
strSQL += ",@Keywords";
strSQL += ",@GroupID";
strSQL += ",@FileTypeID";
strSQL += ",@FileName";
strSQL += ",@BinaryFile";
//strSQL += ",@DateUpdated";
//strSQL += ",@DateCreated";
strSQL += ",@DateAdded";
strSQL += ",@isActive";
strSQL += ",@SiteID";
strSQL += ")";
SqlCommand cmdInsert = new SqlCommand(strSQL, con);
cmdInsert.Parameters.AddWithValue("@Title", strFileTitle);
cmdInsert.Parameters.AddWithValue("@Subject", tbxFileSubject.Text);
cmdInsert.Parameters.AddWithValue("@Description", tbxFileDescription.Text);
cmdInsert.Parameters.AddWithValue("@Keywords", tbxFileKeywords.Text);
cmdInsert.Parameters.AddWithValue("@GroupID", ddlFileEditorGroup.SelectedValue);
cmdInsert.Parameters.AddWithValue("@FileTypeID", strExtension);
cmdInsert.Parameters.AddWithValue("@FileName", file.ClientFileName.ToString().Trim());
cmdInsert.Parameters.AddWithValue("@BinaryFile", imageBytes);
//cmdInsert.Parameters.AddWithValue("@DateUpdated", null);
//cmdInsert.Parameters.AddWithValue("@DateCreated", null);
cmdInsert.Parameters.AddWithValue("@DateAdded", DateTime.Today.ToShortDateString());
cmdInsert.Parameters.AddWithValue("@isActive", cboFileIsActive.Checked);
cmdInsert.Parameters.AddWithValue("@SiteID", intSiteID);
try
{
con.Open();
cmdInsert.ExecuteNonQuery();
if (con.State == ConnectionState.Open)
{ con.Dispose(); }
}
catch (Exception ex)
{
PF.Email.ErrorEmail("Error on INSERT for CMS Files", "CMS Files", "", ex);
}
}
files = null;
fuFiles.ClearPostedFiles();
fuFiles.Dispose();
pnlEditors.Visible = true; // all of these are hidden to speed up code rendering
dsFiles_Selecting(null, null);
}
David L. Sargent Developer Washington State University
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
I've sent you a private message regarding the post, please take a look.
Thanks
|
|