1

我的用户控制代码引发 javascript 错误。

如果我不在主页中包含uplNewRequestCreation,一切都会按预期进行。所有服务器端和客户端文件上传功能都被触发。在主页中包含更新面板的原因是为了避免整页回发。

我尝试了几种来自在线资源的解决方案,但都没有帮助。

  1. 将 scriptmanagerproxy 添加到用户控制页面
  2. 在 page_load 后面的代码中定义了 javascript - 此解决方案有效,但未触发 OnUploadedComplete="uplFile1_UploadedComplete"
  3. 添加文件上传用户控件作为主更新面板的触发器并将更新模式更改为条件

错误消息:初始化 FileUpload.ascx.cs 后,显示以下错误消息。Microsoft JScript 运行时错误:“clientUploadComplete”未定义

非常感谢您的帮助!

谢谢!!!!

这是我的代码结构。

用户控制

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="FileUpload.ascx.cs"
    Inherits="QTrack2.UserControls.FileUpload" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<script type="text/javascript">
    function clientUploadComplete(sender, args) {

        document.getElementById('<%= btnTrigger.ClientID %>').click();
    }
</script>

<div style="float: left; margin-left: 0px;">
    <asp:GridView ID="grdUploadControls" runat="server" AutoGenerateColumns="False" OnRowDataBound="grdUploadControls_RowDataBound"
        CssClass="uploadTable" Caption="CIQ Files Required To Be Uploaded">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Label ID="lblCIQType" CssClass="Label" runat="server" Text='<%#Eval("Key")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField Visible="false">
                <ItemTemplate>
                    <asp:Label ID="isReqlblCIQType" CssClass="Label" runat="server" Text='<%#Eval("Value")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ControlStyle-CssClass=" ">
                <ItemTemplate>
                    <asp:AsyncFileUpload ID="uplFile1" runat="server" OnUploadedComplete="uplFile1_UploadedComplete"
                        CompleteBackColor="#E5FFE5" ErrorBackColor="#F4ADAE" Width="300" UploaderStyle="Modern"
                        ClientIDMode="AutoID" OnClientUploadComplete="clientUploadComplete"/>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:HiddenField ID="hdnFileSavePath" runat="server" Value="" />
    <br />
</div>
<div style="float: left; margin-left: 20px; height: 40%; width: 650px; overflow: auto;
    padding-right: 20px;">
  <%--  <asp:UpdatePanel ID="upnlFileDisplayHolder" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnTrigger" />
        </Triggers>
        <ContentTemplate>--%>
            <asp:GridView ID="grdFileDisplay" runat="server" AutoGenerateColumns="false" CssClass="uploadTable"
                OnRowDataBound="grdFileDisplay_RowDataBound" Caption="CPM Files Currently Uploaded">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Label ID="lblFileType" CssClass="Label" runat="server" Text='<%#Eval("Value")%>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Label ID="lblFileName" CssClass="Label" runat="server" Text='<%#Eval("Key")%>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Button ID="btnDeleteFile" CssClass="button" runat="server" Text="Remove" OnClick="btnDeleteFile_Click" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <div>
                <asp:Button ID="btnTrigger" runat="server" Text="fdkl" Style="display: none;" OnClick="btnTrigger_Click" />
            </div>
       <%-- </ContentTemplate>
    </asp:UpdatePanel>--%>
</div>
<div style="clear: both">
</div>

主页面调用用户控件

<%@ Page Title="New Request" Language="C#" MasterPageFile="~/Site.IM.master" AutoEventWireup="true"
    CodeBehind="GenericNewRequest.aspx.cs" Inherits="QTrack2.CreatorPages.NewRequest.Scripts.Generic.GenericNewRequest" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register TagPrefix="uc1" TagName="fileUploadUserControl" Src="~/UserControls/FileUpload.ascx" %>
<%@ Register TagPrefix="uc2" TagName="ciqValidationUserControl" Src="~/UserControls/ciqValUserControl.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        // This function is called whenever the user selects expected completion date from view # 3.
        // This function checks if the selected date is less than currentDate and sets to the currentDate if true.

        function checkSelectedDate(sender, args) {
            if (sender._selectedDate < new Date()) {
                var previouslySelectedDate = sender._textbox.value;
                sender._selectedDate = new Date();
                // set the date back to the current date
                sender._textbox.set_Value(sender._selectedDate.format(sender._format))
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:UpdatePanel ID="uplNewRequestCreation" runat="server">
    <ContentTemplate>
    <asp:MultiView ID="mviewNewRequestCreation" runat="server" ActiveViewIndex="0">
       <View #1>
        .....
       </View #1>

       <View # 2>
           <uc1:fileUploadUserControl ID="multUplUserCntrol1" runat="server" />
          .....
       </View # 2>

       <View # 3>
       ....
       </View #3>
   </asp:MultiView>
   </ContentTemplate>
</asp:UpdatePanel>
4

1 回答 1

0

很明显,您的 Javascript 函数没有在更新面板中注册,您可以这样做:

  • 在用户控件和更新面板之外声明此函数clientUploadComplete 。

或者您也可以:

  • 调用 document.getElementById('<%= btnTrigger.ClientID %>').click(); 函数不使用javascript函数,像这样......

    OnClientUploadComplete="document.getElementById('btnTrigger_clientName').click()"

于 2018-03-13T17:42:13.353 回答