locked
File Upload Closing PopupExtender RRS feed

  • Question

  • User1556928295 posted

    I've got an UpdatePanel with PopupExtender with a file upload button. When the file gets uploaded, the PopupExtender closes. I want to upload the image file and then display it on the UpdatePanel along with the other images the person has uploaded. Right now, all it does is closes the PopupExtender. I have a Delete button that works great and a set main photo button that also works great, but the upload seems to close the PopupExtender.

    Here's my HTML:

            <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
                <Triggers>
                    <asp:PostBackTrigger ControlID="btnUpload" />
                </Triggers>
                <ContentTemplate>
                    <asp:Button ID="DummyButton" runat="server" Style="display: none" />
                    <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="UpdatePanel3"
                        Enabled="True" TargetControlID="DummyButton" Drag="True" DropShadow="False" CancelControlID="btClose"
                        PopupDragHandleControlID="Panel1">
                    </asp:ModalPopupExtender>
                    <asp:Panel ID="Panel1" runat="server" Style="border-style: none; background-color: #1951B9;
                        text-align: right;">
                        <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Large" Font-Underline="False"
                            Text="PHOTOS" ForeColor="White"></asp:Label>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:Button ID="btClose" runat="server" Text="X" Font-Bold="True" />
                    </asp:Panel>
                    <table class="style1" style="border-style: none; background-color: #FFFFFF" align="center">
                        <tr>
                            <td width="210px" height="210px" bgcolor="Silver">
                                <asp:ImageButton ID="Photo1" runat="server" Height="200px" Width="200px" ImageAlign="AbsMiddle"
                                    BorderColor="Silver" BorderWidth="5px" />
                            </td>
                            <td width="210px" height="210px" bgcolor="Silver">
                                <asp:ImageButton ID="Photo2" runat="server" Height="200px" Width="200px" ImageAlign="AbsMiddle"
                                    BorderColor="Silver" BorderWidth="5px" />
                            </td>
                            <td width="210px" height="210px" bgcolor="Silver">
                                <asp:ImageButton ID="Photo3" runat="server" Height="200px" Width="200px" ImageAlign="AbsMiddle"
                                    BorderColor="Silver" BorderWidth="5px" />
                            </td>
                        </tr>
                        <tr>
                            <td width="210px" height="210px" bgcolor="Silver">
                                <asp:ImageButton ID="Photo4" runat="server" Height="200px" Width="200px" ImageAlign="AbsMiddle"
                                    BorderColor="Silver" BorderWidth="5px" />
                            </td>
                            <td width="210px" height="210px" bgcolor="Silver">
                                <asp:ImageButton ID="Photo5" runat="server" Height="200px" Width="200px" ImageAlign="AbsMiddle"
                                    BorderColor="Silver" BorderWidth="5px" />
                            </td>
                            <td width="210px" height="210px" bgcolor="Silver">
                                <asp:ImageButton ID="Photo6" runat="server" Height="200px" Width="200px" ImageAlign="AbsMiddle"
                                    BorderColor="Silver" BorderWidth="5px" />
                            </td>
                        </tr>
                        <tr>
                            <td width="210px" height="210px" bgcolor="Silver">
                                <asp:ImageButton ID="Photo7" runat="server" Height="200px" Width="200px" ImageAlign="AbsMiddle"
                                    BorderColor="Silver" BorderWidth="5px" />
                            </td>
                            <td width="210px" height="210px" bgcolor="Silver">
                                <asp:ImageButton ID="Photo8" runat="server" Height="200px" Width="200px" ImageAlign="AbsMiddle"
                                    BorderColor="Silver" BorderWidth="5px" />
                            </td>
                            <td width="210px" height="210px" bgcolor="Silver">
                                <asp:ImageButton ID="Photo9" runat="server" Height="200px" Width="200px" ImageAlign="AbsMiddle"
                                    BorderColor="Silver" BorderWidth="5px" />
                            </td>
                        </tr>
                    </table>
                    <asp:Panel runat="server">
                        &nbsp;<asp:FileUpload ID="fileUploadImage" runat="server" Width="400px"></asp:FileUpload>
                        <br />
                        <asp:Button ID="btnUpload" runat="server" Text="Upload Image"/>
                        <asp:Button ID="btSetMainPhoto" runat="server" Text="Set as Main Photo" />
                        <asp:Button ID="btDeletePhoto" runat="server" Text="Delete" />
                        <br />
                        <asp:Label ID="lblError" runat="server" ForeColor="Red" Text="* Must select a photo first."
                            Visible="False"></asp:Label>
                        <asp:Label ID="lblMessage" runat="server" Text="Image uploaded successfully." Visible="False"
                            ForeColor="Green"></asp:Label>
                    </asp:Panel>
                </ContentTemplate>
            </asp:UpdatePanel>

    and my code behind:

        Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpload.Click
            Dim SelectedItem_ImageURL As String = CType(Session.Item("SelectedItem_ImageURL"), String)
            Dim LastPhoto As Integer = GetLastPhoto() + 1

            If (fileUploadImage.HasFile) Then
                fileUploadImage.SaveAs("\\slots\programs\fts\photos\" + SelectedItem_ImageURL + "-" + LastPhoto.ToString + ".jpg")
            End If

            DisplayPhotos()
            ModalPopupExtender1.Show()
            GridView1.Visible = False

        End Sub

        Private Function DisplayPhotos() As Integer
            Dim SelectedItem_ImageURL As String = CType(Session.Item("SelectedItem_ImageURL"), String)

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-1.jpg") Then
                Photo1.ImageUrl = "\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-1.jpg?" + DateTime.Now.Ticks.ToString()
                Photo1.Visible = True
            Else
                Photo1.Visible = False
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-2.jpg") Then
                Photo2.ImageUrl = "\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-2.jpg?" + DateTime.Now.Ticks.ToString()
                Photo2.Visible = True
            Else
                Photo2.Visible = False
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-3.jpg") Then
                Photo3.ImageUrl = "\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-3.jpg?" + DateTime.Now.Ticks.ToString()
                Photo3.Visible = True
            Else
                Photo3.Visible = False
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-4.jpg") Then
                Photo4.ImageUrl = "\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-4.jpg?" + DateTime.Now.Ticks.ToString()
                Photo4.Visible = True
            Else
                Photo4.Visible = False
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-5.jpg") Then
                Photo5.ImageUrl = "\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-5.jpg?" + DateTime.Now.Ticks.ToString()
                Photo5.Visible = True
            Else
                Photo5.Visible = False
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-6.jpg") Then
                Photo6.ImageUrl = "\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-6.jpg?" + DateTime.Now.Ticks.ToString()
                Photo6.Visible = True
            Else
                Photo6.Visible = False
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-7.jpg") Then
                Photo7.ImageUrl = "\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-7.jpg?" + DateTime.Now.Ticks.ToString()
                Photo7.Visible = True
            Else
                Photo7.Visible = False
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-8.jpg") Then
                Photo8.ImageUrl = "\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-8.jpg?" + DateTime.Now.Ticks.ToString()
                Photo8.Visible = True
            Else
                Photo8.Visible = False
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-9.jpg") Then
                Photo9.ImageUrl = "\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-9.jpg?" + DateTime.Now.Ticks.ToString()
                Photo9.Visible = True
            Else
                Photo9.Visible = False
            End If

        End Function

        Private Function GetLastPhoto() As Integer
            Dim SelectedItem_ImageURL As String = CType(Session.Item("SelectedItem_ImageURL"), String)

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-9.jpg") Then
                Return 9
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-8.jpg") Then
                Return 8
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-7.jpg") Then
                Return 7
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-6.jpg") Then
                Return 6
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-5.jpg") Then
                Return 5
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-4.jpg") Then
                Return 4
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-3.jpg") Then
                Return 3
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-2.jpg") Then
                Return 2
            End If

            If File.Exists("\\slots\programs\FTS\photos\" + SelectedItem_ImageURL + "-1.jpg") Then
                Return 1
            End If

        End Function

    Tuesday, November 26, 2013 11:29 AM

Answers

All replies