Re: Various issues with uploader inside a form view a inside update panel

  •  01-13-2010, 2:24 PM

    Re: Various issues with uploader inside a form view a inside update panel

    Here is the code:-
     

    <%@ Page Language="VB" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">

        Private TestDataSource As New Dictionary(Of String, String)

        Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
           
            If Not IsPostBack Then
           
                TestDataSource.Add("FirstItem", "FirstItem")
           
                Dim FormView1 As FormView = DirectCast(UpdatePanel1.FindControl("FormView1"), FormView)
               
                FormView1.DataSource = TestDataSource
                FormView1.DataBind()
               
            End If
           
        End Sub

        Private Sub FormView1_ModeChanging(ByVal sender As Object, ByVal e As FormViewModeEventArgs) Handles FormView1.ModeChanging
            Dim FormView1 As FormView = DirectCast(sender, FormView)
           
            FormView1.ChangeMode(e.NewMode)
            TestDataSource.Add("FirstItem", "FirstItem")
            FormView1.DataSource = TestDataSource
            FormView1.DataBind()
           
        End Sub

        Private Sub InsertMsg(ByVal msg As String)
           
            'Get a handle to the now nested ListBoxEvents
            Dim FormView1 As FormView = DirectCast(UpdatePanel1.FindControl("FormView1"), FormView)
            Dim ListBoxEvents As ListBox = DirectCast(FormView1.FindControl("ListBoxEvents"), ListBox)
           
            ListBoxEvents.Items.Insert(0, msg)
            ListBoxEvents.SelectedIndex = 0
           
        End Sub

        Private Sub ButtonPostBack_Click(ByVal sender As Object, ByVal e As EventArgs)
            InsertMsg("You clicked a PostBack Button.")
        End Sub

        Private Sub Uploader_FileUploaded(ByVal sender As Object, ByVal args As UploaderEventArgs)
            InsertMsg("File uploaded! " & args.FileName & ", " & args.FileSize & " bytes.")
            'Copys the uploaded file to a new location.
            'args.CopyTo("c:\\temp\\"& args.FileName)
            'You can also open the uploaded file's data stream.
            'System.IO.Stream data = args.OpenStream();
        End Sub
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Simple Upload</title>
        <link rel="stylesheet" href="demo.css" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="content">
                <%= DateTime.Now%>
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                    <%= DateTime.Now%>
                    <asp:FormView ID="FormView1" DefaultMode="ReadOnly" runat="server">
                    <ItemTemplate>
                    <asp:LinkButton ID="Edit" Text="Edit" CommandName="Edit" runat="server" />
                    <p>You are not in edit mode</p>
                    </ItemTemplate>
                   
                    <EditItemTemplate>
                        <%= DateTime.Now%>
                        <h2>
                            Simple Upload (Customizing the UI)
                        </h2>
                        <p>
                            A sample demonstrating how to customize the look and feel of file upload controls.
                            (Maximum file size: 10M).
                        </p>
                     
                        <asp:Image runat="server" ID="Uploader1Insert" AlternateText="Upload File" ImageUrl="~/sampleimages/upload.png" />
                        <asp:Panel runat="server" ID="Uploader1Progress" BorderColor="Orange" BorderStyle="dashed"
                            BorderWidth="2" Style="padding-right: 4px; padding-left: 4px; padding-bottom: 4px;
                            padding-top: 4px">
                            <asp:Label ID="Uploader1ProgressText" runat="server" ForeColor="Firebrick"></asp:Label>
                        </asp:Panel>
                        <asp:Image runat="server" ID="Uploader1Cancel" AlternateText="Cancel" ImageUrl="~/sampleimages/cancel_button.gif" />
                        <CuteWebUI:Uploader runat="server" UploadType="IFrame" ID="Uploader1" InsertButtonID='Uploader1Insert'
                            ProgressCtrlID='Uploader1Progress' ProgressTextID='Uploader1ProgressText' CancelButtonID='Uploader1Cancel'
                            OnFileUploaded="Uploader_FileUploaded">
                            <ValidateOption MaxSizeKB="10240" />
                        </CuteWebUI:Uploader>
                        <br />
                        <br />
                        <div>
                            Server Trace:
                            <br />
                            <br />
                            <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>
                        </div>
                        <br />
                        <br />
                       
                        <asp:Button ID="ButtonPostBack" Text="This is a PostBack button" runat="server" OnClick="ButtonPostBack_Click" />
                       
                    </EditItemTemplate>
                    </asp:FormView>
                       
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
        </form>
    </body>
    </html>

View Complete Thread