简体   繁体   English

Microsoft JScript运行时错误:“ clientUploadComplete”未定义

[英]Microsoft JScript runtime error: 'clientUploadComplete' is undefined

My user control code throws javascript error. 我的用户控制代码抛出javascript错误。

If I don't include uplNewRequestCreation in the main page, everything works as expected. 如果我不在主页上包含uplNewRequestCreation ,则一切正常。 All the server and client side file upload functions are triggered. 服务器和客户端的所有文件上传功能均被触发。 The reason for including the update panel in main page is to avoid full page postback. 在主页中包含更新面板的原因是为了避免回发整页。

I have tried several solutions from online sources but none helped. 我已经尝试了几种来自在线资源的解决方案,但是没有一个帮助。

  1. added scriptmanagerproxy to user control page 向用户控制页面添加了scriptmanagerproxy
  2. defined the javascript in code behind page_load - this solution worked, but it did not trigger OnUploadedComplete="uplFile1_UploadedComplete" 在page_load后面的代码中定义了javascript-此解决方案有效,但未触发OnUploadedComplete =“ uplFile1_UploadedComplete”
  3. added file upload user control as trigger to the main update panel and changed updatemode to conditional 将文件上传用户控件添加为主更新面板的触发器,并将updatemode更改为有条件的

Error message: After the FileUpload.ascx.cs is initialized, following error message is shown. 错误消息:初始化FileUpload.ascx.cs后,显示以下错误消息。 Microsoft JScript runtime error: 'clientUploadComplete' is undefined Microsoft JScript运行时错误:“ clientUploadComplete”未定义

I appreciate your help very much! 非常感谢您的帮助!

Thanks!!!! 谢谢!!!!

Here's my code structure. 这是我的代码结构。

User control 用户控制

<%@ 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>

Main page calling user control 主页调用用户控件

<%@ 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>

It is clear your Javascript function is not being registered within the update panel, you can do this: 很明显,您的Javascript函数未在更新面板中注册,您可以执行以下操作:

  • Declare this function clientUploadComplete outside the User Control and outside the Update Panel. 在用户控件外部和更新面板外部声明此功能clientUploadComplete

Or also you can: 或者,您也可以:

  • Call the document.getElementById('<%= btnTrigger.ClientID %>').click(); 调用document.getElementById('<%= btnTrigger.ClientID%>')。click(); function not using a javascript function, something like this... 函数未使用javascript函数,类似这样...

    OnClientUploadComplete="document.getElementById('btnTrigger_clientName').click()" OnClientUploadComplete =“ document.getElementById('btnTrigger_clientName')。click()”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft JScript运行时错误“ btn_click”未定义 - microsoft jscript runtime error 'btn_click' is undefined BHO插件(Microsoft JScript运行时错误) - BHO Plugin (Microsoft JScript runtime error) jQuery“Microsoft JScript运行时错误:对象预期” - jQuery “Microsoft JScript runtime error: Object expected” Fancybox Microsoft JScript 运行时错误:权限被拒绝 - Fancybox Microsoft JScript runtime error: Permission denied Microsoft JScript运行时错误:预期对象 - Microsoft JScript runtime error: Object expected Microsoft JScript运行时错误:“null”为null或不是对象 - Microsoft JScript runtime error: 'null' is null or not an object Microsoft JScript运行时错误:无法获取属性“样式”的值:对象为null或未定义 - Microsoft JScript runtime error: Unable to get value of the property 'style': object is null or undefined Microsoft JScript中的运行时错误:未定义“数组” - Runtime Error in Microsoft JScript: 'Array' is not defined Microsoft JScript运行时错误:无法获取属性&#39;removeChild&#39;的值:对象为null或未定义 - Microsoft JScript runtime error: Unable to get value of the property 'removeChild': object is null or undefined Microsoft JScript运行时错误:&#39;Sys&#39;未定义(在MVC3 C#剃须刀中) - Microsoft JScript runtime error: 'Sys' is undefined (in mvc3 c# razor)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM