我有一个使用DevExpress ASPxUploadControl(v 8.3)的Web表单,可让我们的用户将文档上传到我们的服务器。 我正在开发一项增强功能,使他们可以选择文档的上载文件夹。 这些不是物理文件夹,而是逻辑文件夹。 我已经在表单中添加了一个ASP:DropDownList,它是使用用户设置的文件夹名称从数据库中填充的。 如果用户选择文件夹,然后选择附件,则一切正常。 但是,如果他们选择了要上载的文件,然后选择了文件夹,则一旦选择了文件,文件就会自动上载,而不是等待他们单击“上载”链接。 如果他们选择了错误的文档,则不允许他们进行更改。 另外,使用从下拉列表中选择的旧(最后)值-不会更新以反映新的选择,我怀疑服务器端事件和客户端事件之间存在冲突。 以下是相关代码。 如何防止页面自动上传文档?

谢谢! 麦克风

<td class="style6" valign="middle">
                &nbsp;&nbsp;<asp:Panel ID="Panel3" colspan="2" runat="server" Height="83px" Width="125px"
                    Style="margin-top: 0px">
                                <dxuc:ASPxUploadControl ID="uplImage" runat="server" 
                                ClientInstanceName="uploader" Font-Size="Medium" Height="84px" 
                                OnFileUploadComplete="uplImage_FileUploadComplete" ShowUploadButton="True" 
                                Size="50" style="margin-top: 0px; margin-right: 2px;">

                                    <ValidationSettings AllowedContentTypes="image/jpeg,image/gif,image/pjpeg,application/pdf,application/rtf,application/msword,application/vnd.ms-excel,application/csv,text/plain,text/csv,text/richtext,text/rtf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, audio/wav" MaxFileSize="4096000">
                                        <ErrorStyle Font-Size="Smaller" />
                                    </ValidationSettings>
                                    <ClientSideEvents FileUploadComplete="function(s, e) {
                            if(e.isValid)
                            {
                                if(e.errorText != ''){
                                    alert(e.errorText);
                                } else {
                                    alert(e.callbackData);
                                }
                            }
                        }" />
                        <ValidationSettings AllowedContentTypes="image/jpeg, image/gif, image/pjpeg, application/pdf, application/rtf, application/msword, application/vnd.ms-excel, application/csv, text/plain, text/csv, text/richtext, text/rtf, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, audio/wav"
                            MaxFileSize="4096000">
                            <ErrorStyle Font-Size="Smaller" />
                        </ValidationSettings>
                                    <ClientSideEvents FilesUploadComplete="function(s, e) {}" FileUploadComplete="function(s, e) {
                            if(e.isValid)
                            {
                                if(e.errorText != ''){
                                    alert(e.errorText);
                                } else {
                                    alert(e.callbackData);
                                }
                            }
                        }" FileUploadStart="function(s, e) {}" />

                    </dxuc:ASPxUploadControl>

                </asp:Panel>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td colspan="2" class="txtnote" align="center" style="height: 18px">
                Allowed file types: jpeg, gif, pdf, rtf, doc, docx, txt, csv, xls, xlsx, wav
            </td>
        </tr>
        <tr>
            <td colspan="2" class="txtnote" align="center" style="height: 10px">
                Maximum file size: 4Mb
            </td>
        </tr>
        <tr>
        <td></td>
        <td>
            <input id="chkPrivate" name="chkPrivate"  value="1" type="checkbox"/>Private 
            (checking Private prevents Mgmt Co &amp;Assn from viewing attachment via client 
            login.)</td></tr>            
        <tr class="aligncenter">
            <th class="style5" align="center" colspan="2">
                &nbsp;</th>
        </tr>
        <tr class="aligncenter">
            <th class="style5" align="center" colspan="2">
                <asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px">
                    <%--<dxe:ASPxButton ID="Button1" runat="server" Font-Size="Medium" Text="Cancel">
                        <Paddings PaddingLeft="10px" PaddingRight="10px" />
                    </dxe:ASPxButton>--%>
                    <input type="button" id="btnReturn" class="frmBtnCommon" value="Back To Case" onclick="ReturnToCase();" />
                </asp:Panel>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim DAL As New DataAccessLayer
        Dim dtFolders As New DataTable

        GlobalVar.LoadData(Session("UserPKey"))

        Session("CurrentPage") = "CaseAttchmt.aspx"
        If Session("LoggedOn") = True And GlobalVar.ConnectString <> "" Then
            CSSDefaultHTML = Session("CSS_Default")
            DefaultIPHTML = Application("DefaultIP")
        End If

        SelKey = Request.QueryString("Case")

        Header1.ConnectionStr = GlobalVar.ConnectString
        Header1.HDLawFirm = GlobalVar.LawFirmDir
        Header1.InsertHeader("Add File to a Case", 0, 0, SelKey, "width=100% align=center")
        ClientKey = Session("ClientKey")
        UploadDirectory = GlobalVar.LawFirmDir & "AttachFiles/Case" & Trim(Str(SelKey)) & "/"

        If System.IO.Directory.Exists(GlobalVar.LawFirmDir & "AttachFiles/") = False Then
            System.IO.Directory.CreateDirectory(GlobalVar.LawFirmDir & "AttachFiles")
        End If

        If System.IO.Directory.Exists(GlobalVar.LawFirmDir & "AttachFiles/Case" & Trim(Str(SelKey))) = False Then
            System.IO.Directory.CreateDirectory(GlobalVar.LawFirmDir & "AttachFiles/Case" & Trim(Str(SelKey)))
        End If

        GlobalVar.SaveData(Session("UserPKey"))

        dtFolders = DAL.GetClientFolders(Session("ClientKey"))
        ddlFolders.DataSource = dtFolders
        Dim lstFolders As ListItem
        Dim i As Integer
        Dim intValue As Integer
        Dim strText As String

        If Not Page.IsPostBack Then
            ddlFolders.Items.Clear
            intValue = 0
            strText = "Attachments"
            lstFolders = New ListItem(strText, intValue)
            ddlFolders.Items.Add(lstFolders)

            For i = 0 to dtFolders.Rows.Count - 1
                intValue = dtFolders.Rows(i).Item("pKey")
                strText = dtFolders.Rows(i).Item("FolderName")
                lstFolders = New ListItem(strText, intValue)
                ddlFolders.Items.Add(lstFolders)
            Next
            ddlFolders.SelectedIndex = 0
            Session("FolderKey") = 0
        End If

    End Sub

    Protected Function SavePostedFile() As String

        Dim filename As String = ""
        Dim tempFileName As String = ""
        SelKey = Session("SelKey")
        If Len(Trim(Session("ClientKey"))) = 4 then
            UploadDirectory = "~/DATA/AR00" & Session("ClientKey") & "/AttachFiles/Case" & Trim(Str(SelKey)) & "/"
        Else
            UploadDirectory = "~/DATA/" & Trim(Session("LawFirm")) & "/AttachFiles/Case" & Trim(Str(SelKey)) & "/"
        End If

        filename = Trim(uplImage.FileName)

        If filename <> "" Then
            tempFileName = MapPath(UploadDirectory) & filename
            uplImage.SaveAs(tempFileName)
        End If
        Return tempFileName

    End Function

    Protected Sub uplImage_FileUploadComplete(ByVal sender As Object, ByVal e As FileUploadCompleteEventArgs)

        Dim FileExists As Boolean = False
        UploadDirectory = "~/DATA/" & Trim(Session("LawFirm")) & "/AttachFiles/Case" & Trim(Str(Session("SelKey"))) & "/"

        Dim FilePath As String = MapPath(UploadDirectory) & Trim(uplImage.FileName)

        FileExists = CheckForFile(FilePath)

        'urk : Added validation for checking filename length and filesize being uploaded 06/01/2010.
        If (e.IsValid) Then
            If (e.UploadedFile.FileName.Length > 100) Then
                e.ErrorText = "The file name cannot be more than 100 characters long.  Please shorten and retry."
            ElseIf (e.UploadedFile.FileName.Contains("'") Or e.UploadedFile.FileName.Contains("&")) Then
                e.ErrorText = "The file name cannot contain the apostrophe or ampersand characters."
            ElseIf (e.UploadedFile.FileName.EndsWith(".aspx")) Or (e.UploadedFile.FileName.EndsWith(".ASPX")) Then
                e.ErrorText = ".aspx files are not allowed for upload."
            ElseIf FileExists = True Then
                e.ErrorText = "A file with this name has already been uploaded.  Please rename and try again."
            Else
                e.CallbackData = SavePostedFile()
                If e.CallbackData <> "" Then
                    s_UpdateAttachData()
                End If
                e.CallbackData = "File: '" + e.UploadedFile.FileName + "' uploaded successfully."
            End If
        End If

    End Sub

    Private Sub s_UpdateAttachData()

        Dim i_date As DateTime = Now.Date
        Dim DAL As New DataAccessLayer

        ClientKey = Session("ClientKey")
        Dim pPrintBy As Integer = Session("UserPKey")
        Dim PrintDate As DateTime = Now
        Dim s As Boolean
        Dim FullAttchPath As String

        If Len(trim(ClientKey)) = 1 Then
            FullAttchPath = "DATA/AR00000" + ClientKey.ToString + "/AttachFiles/Case" + SelKey.ToString + "/" + Trim(uplImage.FileName)
        ElseIf Len(Trim(ClientKey)) = 4 then
            FullAttchPath = "DATA/AR00" + ClientKey.ToString + "/AttachFiles/Case" + SelKey.ToString + "/" + Trim(uplImage.FileName)
        Else
            FullAttchPath = "DATA/AR0" + ClientKey.ToString + "/AttachFiles/Case" + SelKey.ToString + "/" + Trim(uplImage.FileName)
        End If
        If Request.Form("chkPrivate") <> "" Then
            s = 1
        Else
            s = 0
        End If

        DAL.InsertCasesAttachPKey(ClientKey, SelKey, Trim(uplImage.FileName), Trim(uplImage.FileName), pPrintBy, PrintDate, s, FullAttchPath, Session("FolderKey"))

    End Sub

    Protected Function CheckForFile(ByVal Filename As String) As Boolean

        If File.Exists(Filename) Then
            Return True
        Else
            Return False
        End If

    End Function

        Protected Sub ddlFolders_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlFolders.SelectedIndexChanged

        Session("FolderKey") = ddlFolders.SelectedValue

    End Sub

  ask by Mike translate from so

本文未有回复,本站智能推荐:

1回复

page_unload之后如何调试asp.net错误-在DropDownList中不能选择多个项目

vb.net具有母版页和许多用户控件。 我们正在构建许多动态控件,包括下拉列表。 Page_Unload事件完成后,立即引发此错误,然后将其捕获在global.asax Application_Error方法中。 “不能在DropDownList中选择多个项目” 堆栈跟踪没有告诉我有
3回复

ASP.NET中的Dropdownlist绑定

假设我在页面中有一个带有数据源的下拉列表,我可以创建下拉列表,它会自动使用datasrouce中的数据进行填充,我不需要使用.bind()方法,但为什么我仍然看到一些程序员仍在使用Page_Load中的.bind()方法? 如果ASP.NET自动为您完成工作,那么这样做的目的是什么?
5回复

使用C#不能在DropDownList中选择多个项目[关闭]

当我尝试从下拉框“不能在DropDownList中选择多个项目”中选择项目时,我收到此错误。 有人可以帮助我,我不知道为什么我得到这个。 这是我的代码: 这是我在aspx中的下拉框 这是页面加载的代码: 这是调用GetGroupNameList的方法:
2回复

从ASP.NETC#中的DropDownList删除项目

我的ASPX页面中有一个DropDownList: 同样基于条件,我在后面的代码中填充了DropDownList: 当我这样做时,我不希望从ASP.NET页标记中填充DropDownList。 即我想从aspx代码中删除添加的项目(仅其中两个)。 有什么帮助吗?
1回复

获取DropDownList值

我从DropDownList中获取值时遇到问题。 我知道如何使用数字来输入值并获得该值,但是我的问题是我必须先输入一个值,例如FrBrb,然后在代码中获取该值并将其设置为40。 这是我到目前为止的内容: 这是我的DropDownList,其中包含字母值。 我必须使用这些值,但不能使用数
2回复

具有不存在的SelectedValue的DropDownList

我有一张表,该表填充了一个名为DropDownList_Tracking_Status的下拉列表。 该表有3列; ID,TrackingName和有效。 当我填写下拉列表时,我提取Active =“ Y”的每条记录。 在将数据读取到表单中时,我正在尝试为DropDownList_Tra
1回复

Gridview项目模板DropDownList已启用

我希望仅在单击Gridview上的编辑链接后禁用DropDownList并启用它。 到目前为止,它显示在编辑链接之前和之后禁用的DropDownList 。 代码: aspx.cs
2回复

RequiredFieldValidator不适用于Dropdownlist

我的网页上有一个Dropdownlist ,如下所示。 但验证器似乎没有发射。 谁能帮我这个?