简体   繁体   中英

AJAX javascript not firing asp.net c#

When I add new controls to my web application, the javascript does not fire. I've tried many solutions, but none of them work. Specifically, the accordion/accordion pane from the AJAX Control Toolkit does not slide up/down. Also the FileUploadProgress control from Obout uses javascript functions which do not fire. If I open a new web application project and try all this, it works just fine. My project is quite large so I cannot start from scratch. Can someone please tell me what could be wrong with my project? I have no errors. The javascript simply does not fire. Please help. I am using asp.net c#.

EDIT:

Here is the code for file upload progress control. I do have alert statements but they do not fire.

    <script type="text/JavaScript">

    function Clear() {
        alert("here1");
        document.getElementById("<%= uploadedFiles.ClientID %>").innerHTML = "";
    }

    function ClearedFiles(fileNames) {
        alert("here2");
        alert("Cleared files with bad extensions:\n\n" + fileNames);
    }

    function Rejected(fileName, size, maxSize) {
        alert("here3");
        alert("File " + fileName + " is rejected \nIts size (" + size + " bytes) exceeds " + maxSize + " bytes");
    }
</script>

<input type="file" name="myFile1" runat="server"/><br/>
<input type="file" name="myFile2"  runat="server"/><br/>
<input type="file" name="myFile3"  runat="server"/><br/>
<input type="submit" value="submit" name="mySubmit" /><br/>
<br/>
<fup:FileUploadProgress ID="FileUploadProgress1" 
   OnClientProgressStopped   = "function(){alert('Files are uploaded to server');}"
   OnClientProgressStarted   = "Clear"
   ShowUploadedFiles         = "true"
   OnClientFileRejected      = "Rejected"
   OnClientFileCleared       = "ClearedFiles"
   runat                     = "server"
>
 <AllowedFileFormats>
      <fup:Format Ext="gif" MaxByteSize="10240"/>
      <fup:Format Ext="jpg" MaxByteSize="10240"/>
      <fup:Format Ext="jpeg" MaxByteSize="10240"/>
      <fup:Format Ext="png" MaxByteSize="10240"/>
 </AllowedFileFormats>
</fup:FileUploadProgress> 
<asp:Label runat="server" id="uploadedFiles" Text="" />

And here's the code-behind for it:

        protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            HttpFileCollection files = Page.Request.Files;

            uploadedFiles.Text = "";

            for (int i = 0; i < files.Count; i++)
            {
                HttpPostedFile file = files[i];
                if (file.FileName.Length > 0)
                {
                    if (uploadedFiles.Text.Length == 0)
                        uploadedFiles.Text += "<b>Successfully uploaded files: </b><table border=0 cellspacing=0>";

                    uploadedFiles.Text += "<tr><td class='option2'>" + file.FileName.Substring(file.FileName.LastIndexOf("\\") + 1) + "</td><td style='font:11px Verdana;'>&nbsp;&nbsp;" + file.ContentLength.ToString() + " bytes</td></tr>";
                }
            }

            if (uploadedFiles.Text.Length == 0)
                uploadedFiles.Text = "no files";
            else
                uploadedFiles.Text += "</table>";
        }

    }

Thanks in advance!!

Looks like it is because you are passing anything to your javascript functions. :

Here is what you have. :

OnClientProgressStarted   = "Clear"
ShowUploadedFiles         = "true"
OnClientFileRejected      = "Rejected"
OnClientFileCleared       = "ClearedFiles"

Here is what I think you should probably have. :

OnClientProgressStarted   = "Clear();"
ShowUploadedFiles         = "true"
OnClientFileRejected      = "Rejected();"
OnClientFileCleared       = "ClearedFiles();"

Also, several of those functions require parameters, which I did not list above......Hopefully this helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM