Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Member
3 Points
16 Posts
Oct 29, 2009 04:15 PM|LINK
Here's a working page using the Northwind database showing the problem.
The page just need to drop the employee table in a dbml.
Thank you all for your help.
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Test</title> <script runat="server"> protected void GvCustomers_SelectedIndexChanged(object sender, EventArgs e) { // set it to true so it will render this.fvCustomerDetail.Visible = true; // force databinding this.fvCustomerDetail.DataBind(); // update the contents in the detail panel this.updPnlCustomerDetail.Update(); // show the modal popup this.mdlPopup.Show(); if (fvCustomerDetail.CurrentMode == FormViewMode.Edit) { string script = "var PhotoImage = '" + fvCustomerDetail.FindControl("PhotoImage").ClientID + "'; var PhotoPathHiddenField = '" + fvCustomerDetail.FindControl("PhotoPathHiddenField").ClientID + "';"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "UploadComplete", script, true); } } protected void LdsCustomerDetail_Selecting(object sender, LinqDataSourceSelectEventArgs e) { // set the input parameter to the value of the selected index if (this.gvCustomers.SelectedIndex >= 0) e.WhereParameters["EmployeeID"] = Convert.ToInt32(this.gvCustomers.DataKeys[this.gvCustomers.SelectedIndex].Value); } protected void GvCustomers_RowCommand(Object sender, GridViewCommandEventArgs e) { switch (e.CommandName) { case "Select": switch (e.CommandArgument.ToString()) { case "Edit": this.fvCustomerDetail.ChangeMode(FormViewMode.Edit); break; case "ReadOnly": this.fvCustomerDetail.ChangeMode(FormViewMode.ReadOnly); break; } break; } } protected void BtnSave_Click(object sender, EventArgs args) { if (this.Page.IsValid) { // move the data back to the data object this.fvCustomerDetail.UpdateItem(false); this.fvCustomerDetail.Visible = false; // hide the modal popup this.mdlPopup.Hide(); // add the css class for our yellow fade ScriptManager.GetCurrent(this).RegisterDataItem( // The control I want to send data to this.gvCustomers, // The data I want to send it (the row that was edited) this.gvCustomers.SelectedIndex.ToString() ); // refresh the grid so we can see our changed this.gvCustomers.DataBind(); this.updatePanel.Update(); } } protected void AsyncFileUploadLogo_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) { ((AjaxControlToolkit.AsyncFileUpload)sender).SaveAs(Server.MapPath(Request.ApplicationPath + "/Photos/" + e.filename)); } </script> <script type="text/javascript"> function UploadComplete(sender, args) { alert("UploadComplete"); $get(PhotoPathHiddenField).value = args.get_fileName(); $get(PhotoImage).src = '<%= Request.ApplicationPath + "/Photos/" %>' + args.get_fileName(); } </script> <style type="text/css"> TR.updated TD { background-color: yellow; } .modalBackground { background-color: Gray; filter: alpha(opacity=70); opacity: 0.7; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="scriptManager" runat="server" /> <script type="text/javascript" language="javascript"> // attach to the pageLoaded event Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded); function pageLoaded(sender, args) { // the data key is the control's ID var dataKey = '<%= this.gvCustomers.ClientID %>'; var updatedRowIndex = args.get_dataItems()[dataKey]; // if there is a datakey for the grid, use it to // identify the row that was updated if (updatedRowIndex) { // get the row that was updated var tr = $get(dataKey).rows[parseInt(updatedRowIndex) + 1]; // add the 'updated' css class Sys.UI.DomElement.addCssClass(tr, 'updated'); // remove the css class in 1.5 seconds window.setTimeout(function() { Sys.UI.DomElement.removeCssClass( tr, 'updated' ); }, 1500); } } </script> <asp:LinqDataSource ID="ldsCustomerList" runat="server" ContextTypeName="NorthwindDataContext" TableName="Employees" Select="new (EmployeeID, LastName, FirstName, Title, Photo, PhotoPath)"> </asp:LinqDataSource> <asp:LinqDataSource ID="ldsCustomerDetail" runat="server" ContextTypeName="NorthwindDataContext" Select="new (EmployeeID, LastName, FirstName, Title, Photo, PhotoPath, Notes)" EnableUpdate="true" TableName="Employees" OnSelecting="LdsCustomerDetail_Selecting" Where="EmployeeID==@EmployeeID"> <WhereParameters> <asp:Parameter DefaultValue="0" Name="EmployeeID" Type="Int32" /> </WhereParameters> </asp:LinqDataSource> <asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:GridView ID="gvCustomers" runat="server" DataSourceID="ldsCustomerList" AutoGenerateColumns="False" OnSelectedIndexChanged="GvCustomers_SelectedIndexChanged" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" DataKeyNames="EmployeeID" OnRowCommand="GvCustomers_RowCommand"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="btnViewDetails" runat="server" Text="View" CommandName="Select" CommandArgument="ReadOnly" /> <asp:LinkButton ID="btnEditDetails" runat="server" Text="Edit" CommandName="Select" CommandArgument="Edit" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" ReadOnly="True" SortExpression="EmployeeID" Visible="false" /> <asp:BoundField DataField="LastName" HeaderText="LastName" ReadOnly="True" SortExpression="LastName" /> <asp:BoundField DataField="FirstName" HeaderText="FirstName" ReadOnly="True" SortExpression="FirstName" /> <asp:BoundField DataField="Title" HeaderText="Title" ReadOnly="True" SortExpression="Title" /> </Columns> <FooterStyle BackColor="#CCCCCC" /> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="#CCCCCC" /> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> <asp:Panel ID="pnlPopup" runat="server" Width="500px" Style="display: none;"> <asp:UpdatePanel ID="updPnlCustomerDetail" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Button ID="btnShowPopup" runat="server" Style="display: none" /> <ajaxToolkit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlPopup" BackgroundCssClass="modalBackground" /> <asp:FormView ID="fvCustomerDetail" runat="server" BackColor="White" BorderColor="#999999" DataSourceID="ldsCustomerDetail" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical"> <FooterStyle BackColor="#CCCCCC" /> <EditItemTemplate> EmployeeID: <%# Eval("EmployeeID") %> <asp:TextBox ID="EmployeeIDTextBox" runat="server" Text='<%# Bind("EmployeeID") %>' /> <br /> LastName: <%# Eval("LastName") %> <asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>' /> <br /> FirstName: <asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' /> <br /> Title: <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' /> <br /> Notes: <asp:TextBox ID="NotesTextBox" runat="server" Text='<%# Bind("Notes") %>' /> <br /> <asp:HiddenField ID="PhotoPathHiddenField" Value='<%# Bind("PhotoPath") %>' runat="server" /> <asp:Image ID="PhotoImage" runat="server" ImageUrl='<%# Request.ApplicationPath + "/Photos/" + Eval("PhotoPath") %>' /><br /> <ajaxToolkit:AsyncFileUpload ID="AsyncFileUploadLogo" runat="server" UploaderStyle="Traditional" OnUploadedComplete="AsyncFileUploadLogo_UploadedComplete" OnClientUploadComplete="UploadComplete" /> <br /> <div> <asp:LinkButton ID="btnSave" runat="server" Text="Save" OnClick="BtnSave_Click" CausesValidation="true" /> <asp:LinkButton ID="btnClose" runat="server" Text="Close" CausesValidation="false" /> </div> </EditItemTemplate> <ItemTemplate> EmployeeID: <asp:Label ID="EmployeeIDLabel" runat="server" Text='<%# Bind("EmployeeID") %>' /> <br /> LastName: <asp:Label ID="LastNameLabel" runat="server" Text='<%# Bind("LastName") %>' /> <br /> FirstName: <asp:Label ID="FirstNameLabel" runat="server" Text='<%# Bind("FirstName") %>' /> <br /> Title: <asp:Label ID="TitleLabel" runat="server" Text='<%# Bind("Title") %>' /> <br /> Notes: <asp:Label ID="NotesLabel" runat="server" Text='<%# Bind("Notes") %>' /> <br /> Photo: <asp:Image ID="PhotoPathLabel" runat="server" ImageUrl='<%# Request.ApplicationPath + "/Photos/" + Eval("PhotoPath") %>' /> <br /> <div> <asp:LinkButton ID="btnClose" runat="server" Text="Close" CausesValidation="false" /> </div> </ItemTemplate> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> </asp:FormView> </ContentTemplate> </asp:UpdatePanel> </asp:Panel> </div> </form> </body> </html>
sovitec
Member
3 Points
16 Posts
Re: AsyncFileUpload : OnUploadedComplete not firing
Oct 29, 2009 04:15 PM|LINK
Here's a working page using the Northwind database showing the problem.
The page just need to drop the employee table in a dbml.
Thank you all for your help.
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Test</title> <script runat="server"> protected void GvCustomers_SelectedIndexChanged(object sender, EventArgs e) { // set it to true so it will render this.fvCustomerDetail.Visible = true; // force databinding this.fvCustomerDetail.DataBind(); // update the contents in the detail panel this.updPnlCustomerDetail.Update(); // show the modal popup this.mdlPopup.Show(); if (fvCustomerDetail.CurrentMode == FormViewMode.Edit) { string script = "var PhotoImage = '" + fvCustomerDetail.FindControl("PhotoImage").ClientID + "'; var PhotoPathHiddenField = '" + fvCustomerDetail.FindControl("PhotoPathHiddenField").ClientID + "';"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "UploadComplete", script, true); } } protected void LdsCustomerDetail_Selecting(object sender, LinqDataSourceSelectEventArgs e) { // set the input parameter to the value of the selected index if (this.gvCustomers.SelectedIndex >= 0) e.WhereParameters["EmployeeID"] = Convert.ToInt32(this.gvCustomers.DataKeys[this.gvCustomers.SelectedIndex].Value); } protected void GvCustomers_RowCommand(Object sender, GridViewCommandEventArgs e) { switch (e.CommandName) { case "Select": switch (e.CommandArgument.ToString()) { case "Edit": this.fvCustomerDetail.ChangeMode(FormViewMode.Edit); break; case "ReadOnly": this.fvCustomerDetail.ChangeMode(FormViewMode.ReadOnly); break; } break; } } protected void BtnSave_Click(object sender, EventArgs args) { if (this.Page.IsValid) { // move the data back to the data object this.fvCustomerDetail.UpdateItem(false); this.fvCustomerDetail.Visible = false; // hide the modal popup this.mdlPopup.Hide(); // add the css class for our yellow fade ScriptManager.GetCurrent(this).RegisterDataItem( // The control I want to send data to this.gvCustomers, // The data I want to send it (the row that was edited) this.gvCustomers.SelectedIndex.ToString() ); // refresh the grid so we can see our changed this.gvCustomers.DataBind(); this.updatePanel.Update(); } } protected void AsyncFileUploadLogo_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) { ((AjaxControlToolkit.AsyncFileUpload)sender).SaveAs(Server.MapPath(Request.ApplicationPath + "/Photos/" + e.filename)); } </script> <script type="text/javascript"> function UploadComplete(sender, args) { alert("UploadComplete"); $get(PhotoPathHiddenField).value = args.get_fileName(); $get(PhotoImage).src = '<%= Request.ApplicationPath + "/Photos/" %>' + args.get_fileName(); } </script> <style type="text/css"> TR.updated TD { background-color: yellow; } .modalBackground { background-color: Gray; filter: alpha(opacity=70); opacity: 0.7; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="scriptManager" runat="server" /> <script type="text/javascript" language="javascript"> // attach to the pageLoaded event Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded); function pageLoaded(sender, args) { // the data key is the control's ID var dataKey = '<%= this.gvCustomers.ClientID %>'; var updatedRowIndex = args.get_dataItems()[dataKey]; // if there is a datakey for the grid, use it to // identify the row that was updated if (updatedRowIndex) { // get the row that was updated var tr = $get(dataKey).rows[parseInt(updatedRowIndex) + 1]; // add the 'updated' css class Sys.UI.DomElement.addCssClass(tr, 'updated'); // remove the css class in 1.5 seconds window.setTimeout(function() { Sys.UI.DomElement.removeCssClass( tr, 'updated' ); }, 1500); } } </script> <asp:LinqDataSource ID="ldsCustomerList" runat="server" ContextTypeName="NorthwindDataContext" TableName="Employees" Select="new (EmployeeID, LastName, FirstName, Title, Photo, PhotoPath)"> </asp:LinqDataSource> <asp:LinqDataSource ID="ldsCustomerDetail" runat="server" ContextTypeName="NorthwindDataContext" Select="new (EmployeeID, LastName, FirstName, Title, Photo, PhotoPath, Notes)" EnableUpdate="true" TableName="Employees" OnSelecting="LdsCustomerDetail_Selecting" Where="EmployeeID==@EmployeeID"> <WhereParameters> <asp:Parameter DefaultValue="0" Name="EmployeeID" Type="Int32" /> </WhereParameters> </asp:LinqDataSource> <asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:GridView ID="gvCustomers" runat="server" DataSourceID="ldsCustomerList" AutoGenerateColumns="False" OnSelectedIndexChanged="GvCustomers_SelectedIndexChanged" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" DataKeyNames="EmployeeID" OnRowCommand="GvCustomers_RowCommand"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="btnViewDetails" runat="server" Text="View" CommandName="Select" CommandArgument="ReadOnly" /> <asp:LinkButton ID="btnEditDetails" runat="server" Text="Edit" CommandName="Select" CommandArgument="Edit" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" ReadOnly="True" SortExpression="EmployeeID" Visible="false" /> <asp:BoundField DataField="LastName" HeaderText="LastName" ReadOnly="True" SortExpression="LastName" /> <asp:BoundField DataField="FirstName" HeaderText="FirstName" ReadOnly="True" SortExpression="FirstName" /> <asp:BoundField DataField="Title" HeaderText="Title" ReadOnly="True" SortExpression="Title" /> </Columns> <FooterStyle BackColor="#CCCCCC" /> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="#CCCCCC" /> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> <asp:Panel ID="pnlPopup" runat="server" Width="500px" Style="display: none;"> <asp:UpdatePanel ID="updPnlCustomerDetail" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Button ID="btnShowPopup" runat="server" Style="display: none" /> <ajaxToolkit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlPopup" BackgroundCssClass="modalBackground" /> <asp:FormView ID="fvCustomerDetail" runat="server" BackColor="White" BorderColor="#999999" DataSourceID="ldsCustomerDetail" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical"> <FooterStyle BackColor="#CCCCCC" /> <EditItemTemplate> EmployeeID: <%# Eval("EmployeeID") %> <asp:TextBox ID="EmployeeIDTextBox" runat="server" Text='<%# Bind("EmployeeID") %>' /> <br /> LastName: <%# Eval("LastName") %> <asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>' /> <br /> FirstName: <asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' /> <br /> Title: <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' /> <br /> Notes: <asp:TextBox ID="NotesTextBox" runat="server" Text='<%# Bind("Notes") %>' /> <br /> <asp:HiddenField ID="PhotoPathHiddenField" Value='<%# Bind("PhotoPath") %>' runat="server" /> <asp:Image ID="PhotoImage" runat="server" ImageUrl='<%# Request.ApplicationPath + "/Photos/" + Eval("PhotoPath") %>' /><br /> <ajaxToolkit:AsyncFileUpload ID="AsyncFileUploadLogo" runat="server" UploaderStyle="Traditional" OnUploadedComplete="AsyncFileUploadLogo_UploadedComplete" OnClientUploadComplete="UploadComplete" /> <br /> <div> <asp:LinkButton ID="btnSave" runat="server" Text="Save" OnClick="BtnSave_Click" CausesValidation="true" /> <asp:LinkButton ID="btnClose" runat="server" Text="Close" CausesValidation="false" /> </div> </EditItemTemplate> <ItemTemplate> EmployeeID: <asp:Label ID="EmployeeIDLabel" runat="server" Text='<%# Bind("EmployeeID") %>' /> <br /> LastName: <asp:Label ID="LastNameLabel" runat="server" Text='<%# Bind("LastName") %>' /> <br /> FirstName: <asp:Label ID="FirstNameLabel" runat="server" Text='<%# Bind("FirstName") %>' /> <br /> Title: <asp:Label ID="TitleLabel" runat="server" Text='<%# Bind("Title") %>' /> <br /> Notes: <asp:Label ID="NotesLabel" runat="server" Text='<%# Bind("Notes") %>' /> <br /> Photo: <asp:Image ID="PhotoPathLabel" runat="server" ImageUrl='<%# Request.ApplicationPath + "/Photos/" + Eval("PhotoPath") %>' /> <br /> <div> <asp:LinkButton ID="btnClose" runat="server" Text="Close" CausesValidation="false" /> </div> </ItemTemplate> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> </asp:FormView> </ContentTemplate> </asp:UpdatePanel> </asp:Panel> </div> </form> </body> </html>