在ASP.NET VB中,如何维护文件上载重新执行向导?

时间:2013-03-04 19:59:28

标签: asp.net vb.net webforms

我有一个带有7个步骤的asp:向导 - 在某一点上,用户可以看到上传文件的选项,或者提供指向互联网上现有文件的链接。

在向导结束时,所有信息都会显示出来进行验证,每个部分都有按钮,以便他们可以返回并编辑某些内容(如果他们拼错了名字)。

在调试中,我发现如果我选择上传文件,它将一直保持到表格结束,但如果我决定返回并编辑任何内容,则文件上传将会消失。

我有什么东西可以保留,或者有可能吗?我会发布相关代码(有很多,它的形式很大)

在.aspx

                    <asp:WizardStep ID="uploadFileWiz" runat="server" Title="Upload File">
                        <!-- Step 4 - Upload a file -->
                        <table>
                            <tr>
                                <th colspan="2" class="alignCenter">
                                    <%:uploadFileWiz.Title %>
                                </th>
                            </tr>
                            <tr>
                                <td class="alignRight">
                                    File Location:
                                </td>
                                <td class="alignLeft">
                                    <asp:FileUpload ID="uploadFile" runat="server" CssClass="inputBox" />
                                </td>
                            </tr>
                            <tr>
                                <td class="alignRight">
                                    Is there a Password?
                                </td>
                                <td class="alignLeft">
                                    <asp:RadioButtonList ID="uploadPasswordFlag" runat="server">
                                        <asp:ListItem>Yes</asp:ListItem>
                                        <asp:ListItem Selected="True">No</asp:ListItem>
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                        </table>
                    </asp:WizardStep>

............................................
                    <asp:WizardStep ID="grandFinale" runat="server" Title="Lets Finish Up">
                        <!-- Step 7 - The final step. Verify information -->
                        <div class="margins">
                            <span class="label">
                                Lets Review:
                            </span>
                            <table>
                                <tr>
                                    <th class="alignRight">
                                        Contact Name:
                                    </th>
                                    <td class="alignLeft">
                                        <%:contactName.Text%>
                                    </td>
                                    <th class="alignRight">
                                        Project Name:
                                    </th>
                                    <td class="alignLeft">
                                        <%:projectName.Text%>
                                    </td>
                                </tr>
                                <tr>
                                    <th class="alignRight">
                                        Contact Email:
                                    </th>
                                    <td class="alignLeft">
                                        <%:contactEmail.Text%>
                                    </td>
                                    <th class="alignRight">
                                        Project Location:
                                    </th>
                                    <td class="alignLeft">
                                        <%:projectLocation.Text%>
                                    </td>
                                </tr>
                                <tr>
                                    <th class="alignRight">
                                        Company:
                                    </th>
                                    <td class="alignLeft">
                                        <%:contactCompany.Text%>
                                    </td>
                                    <th class="alignRight">
                                        General Contractor:
                                    </th>
                                    <td class="alignLeft">
                                        <%:projectContractor.Text%>
                                    </td>
                                </tr>
                                <tr>
                                    <th class="alignRight">
                                        Phone Number:
                                    </th>
                                    <td class="alignLeft">
                                        <%:contactPhone.Text%>
                                    </td>
                                    <th class="alignRight">
                                        Bid Type:
                                    </th>
                                    <td class="alignLeft">
                                        <%:bidType.SelectedValue%>
                                    </td>
                                </tr>
                                <!-- Buttons to go back and edit, if needed -->
                                <tr>
                                    <td colspan="2" class="alignCenter">
                                        <asp:Button ID="goToContactInfo" runat="server" Text="Edit Contact Information" CssClass="inputBox" />
                                    </td>
                                    <td colspan="2" class="alignCenter">
                                        <asp:Button ID="goToProjectInfo" runat="server" Text="Edit Project Information" CssClass="inputBox" />
                                    </td>
                                </tr>
                                <tr>
                                    <th class="alignRight">
                                        File:
                                    </th>
                                    <td class="alignLeft">
                                        <%:getFileInfo()%>
                                    </td>
                                    <th class="alignRight">
                                        Password:
                                    </th>
                                    <td class="alignLeft">
                                        <%:getPasswordInfo()%>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2" class="alignCenter">
                                        <asp:Button ID="goToFileLink" runat="server" Text="Edit File Info" CssClass="inputBox" />
                                    </td>
                                    <td colspan="2" class="alignCenter">
                                        <asp:Button ID="goToPassword" runat="server" Text="Edit Password" CssClass="inputBox" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </asp:WizardStep>

在代码隐藏中......

'##### Edit button handlers
Protected Sub goToContactInfo_Click(sender As Object, e As EventArgs) Handles goToContactInfo.Click
    rqBidWizard.ActiveStepIndex = 0
End Sub

Protected Sub goToProjectInfo_Click(sender As Object, e As EventArgs) Handles goToProjectInfo.Click
    rqBidWizard.ActiveStepIndex = 1
End Sub

Protected Sub goToFileLink_Click(sender As Object, e As EventArgs) Handles goToFileLink.Click
    If selectFile.SelectedValue = "Attach File" Then
        rqBidWizard.ActiveStepIndex = 4
    Else
        rqBidWizard.ActiveStepIndex = 5
    End If
End Sub

Protected Sub goToPassword_Click(sender As Object, e As EventArgs) Handles goToPassword.Click
    rqBidWizard.ActiveStepIndex = 6
End Sub

'##### String parsing functions
Protected Function getPasswordInfo() As String
    Dim isPassword As Boolean = False
    Dim thePassword As String = Nothing
    If uploadPasswordFlag.SelectedValue = "Yes" Or LinkPasswordFlag.SelectedValue = "Yes" Then
        isPassword = True
        thePassword = password1.Text
    End If
    If isPassword Then
        getPasswordInfo = "Yes: " & thePassword
    Else
        getPasswordInfo = "No"
    End If
End Function
Protected Function getFileInfo() As String
    Dim fileType As String = Nothing, fileName As String = Nothing, fileURL As String = Nothing
    Select Case selectFile.SelectedValue
        Case "Attach File"
            fileType = "Uploaded"
            If uploadFile.HasFile Then
                fileName = IO.Path.GetFileName(uploadFile.PostedFile.FileName)
            Else
                fileName = "None"
            End If
            fileURL = Nothing
        Case "Provide Link"
            fileType = "Link"
            fileName = Nothing
            fileURL = Trim(provideLink.Text)
    End Select
    getFileInfo = fileType & ": "
    If fileType = "Uploaded" Then
        getFileInfo = getFileInfo & fileName
    Else
        getFileInfo = getFileInfo & fileURL
    End If
End Function

1 个答案:

答案 0 :(得分:0)

如果您的意思是在某个向导步骤中,用户使用文件上传控件来选择一个文件,但是当它们进一步前进然后返回时,文件上传控件为空...我很抱歉说这就是文件上传控件的工作原理。

每次更改向导步骤时,都会回发并重新加载页面。因此,用户提供的内容将丢失。您可能认为可以在服务器上以编程方式设置控件的文件名,但这不起作用 - 这是正确的,因为它是一个很大的安全漏洞。 (您希望如何浏览可以决定要上传哪些文件的网页?)

你可能需要稍微重新组织你的向导才能解决这个问题。