-1

我在使用javascript函数的aspx文件中有一个aspx,aspx.cs文件,

在 javascript 代码中,我使用在 aspx.cs 文件中定义的 getter (<%=getSize%>) 方法,

但是页面返回:“控件集合无法修改,因为控件包含代码块”为什么?

 <!-- language-all:lang-js -->
 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="uploadFile.aspx.cs"
Inherits="UploadControl_CustomProgressPanel" Title="Untitled Page" %>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
var size = <%=getSize%>;
var id= 0;

function ProgressBar() 
{
if(document.getElementById("FileUpload1").value != "")
{
    document.getElementById("divProgress").style.display = "block";
    document.getElementById("divUpload").style.display = "block";
    id = setInterval("progress()",20);
    return true;
}
else
{
    alert("Select a file to upload");
    return false;
}    

}

function progress()
{
//size = size + 1;
if(size > 299) 
{
    clearTimeout(id);
 }
document.getElementById("divProgress").style.width =  size + "pt";
document.getElementById("lblPercentage").firstChild.data = parseInt(size / 3) +  "%";
}

aspx.cs 文件:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class UploadControl_CustomProgressPanel : System.Web.UI.Page 
{   

   protected int size = 2;

   protected int getSize{ get { return this.size; }}


   protected void Page_Load(object sender, EventArgs e)
    {
    string UpPath;
    UpPath = "C:\\";
    if (! Directory.Exists(UpPath))
    {
        Directory.CreateDirectory("C:\\");      
    }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    //StatusLabel.Text = "File scelto, Upload in corso..";
    if(FileUpload1.HasFile)
    {
        try
        {   
            string filePath = Request.PhysicalApplicationPath;
            filePath += "classic/hub/csv/";
            filePath += FileUpload1.FileName;
            this.size = 50;
            FileUpload1.SaveAs(filePath);
            //StatusLabel.Text = "Upload status: File uploaded!";
            Label1.Text = "Upload successfull!";
        }
        catch(Exception ex)
        {
            //StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
        }
        }
    }
    }
4

2 回答 2

1

您尚未发布完整的 HTML,但尝试将您的脚本移出<head>标签。

于 2013-01-15T16:06:16.393 回答
0

getSize属性还是函数?如果它的属性大小将采用它在页面加载时的值,如果它是一个函数,那么您需要查看页面方法,因为您不能以这种方式调用它,这是一个示例

于 2013-01-15T15:46:31.880 回答