Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试在更新面板内使用ASCX控件进行文件上载_C#_Asp.net_File Upload_Ascx - Fatal编程技术网

C# 尝试在更新面板内使用ASCX控件进行文件上载

C# 尝试在更新面板内使用ASCX控件进行文件上载,c#,asp.net,file-upload,ascx,C#,Asp.net,File Upload,Ascx,因此,我有一个ascx控件用于文件上传。此控件具有文件上载元素和表中的图像按钮,以及网格,以在完成时显示上载的文件。 网格和文件上传+图像按钮表格永远不会同时可见 imagebutton的单击事件位于ascx.cs文件中: public void btnUploadFile_Click(object sender, EventArgs e) { try { if (fileUpload.HasFile)

因此,我有一个
ascx
控件用于文件上传。此控件具有
文件上载
元素和
表中的
图像按钮
,以及
网格
,以在完成时显示上载的文件。
网格
文件上传
+
图像按钮
表格
永远不会同时可见

imagebutton
的单击事件位于ascx.cs文件中:

    public void btnUploadFile_Click(object sender, EventArgs e)
    {
        try
        {
            if (fileUpload.HasFile)
            //if(!string.IsNullOrEmpty(fileUpload.FileName))
            {
                String fileName = fileUpload.FileName;// strPath.Substring(lastIndex + 1);
                String ext = fileUpload.FileName.Split('.')[1];
                Guid newFileName = Guid.NewGuid();
                string strPath = MapPath("~/importfiles/") + newFileName.ToString() + "." + ext;
                fileUpload.SaveAs(strPath);
                LoadTable(fileName);
                hfFilePath.Value = strPath;
                hfFileName.Value = fileName;
                hfMIMEType.Value = fileUpload.PostedFile.ContentType;
                hfFileGUID.Value = newFileName.ToString();
                hfFileUploaded.Value = "1";
            }
            else
            {
                grdAttachment.Visible = false;
                filePickTable.Visible = true;
            }
        }
        catch (Exception ex)
        {
            UserInterfaceExceptionHandler.HandleException(ref ex);
        }
    }
在内容页面上,我必须测试控件是否已经有文件,以便知道要显示控件的哪个视图(grid vs fileupload)

现在我面临的问题是
else
代码(当没有文件时),我得到以下异常:

在UpdatePanel“IssueUpdatePanel”中的触发器的关联控件“btnUploadFile”上找不到名为“Click”的事件

该页面有一个
计时器
,每隔几秒钟自动刷新一次页面

我试着到处寻找解决办法,但没有结果。
希望我已经在这里提供了足够的信息。

你能发布你的ASPX代码吗?@lucidgold:你想要控件的标记还是我试图使用它的页面?好吧,我试图理解“找不到名为“单击”的事件”。您没有在您的ASPX页面中声明它吗?你确定你的ASCX中有它吗?@lucidgold:是的,单击事件在ASCX.cs文件中。我正在aspx.cs文件中创建触发器,试图在其中实现控件。这与此线程上建议的解决方案相同:在哪一行代码上出现此错误?ELSE在哪个方法中执行?
if (attr.ImageValue != null)
{
    //Do stuff to display grid instead of fileupload control
    PostBackTrigger newTrigger = new PostBackTrigger();
    newTrigger.ControlID = attrControl.ID;
    IssueUpdatePanel.Triggers.Add(newTrigger);
}
else
{
    (attrControl.FindControl("filePickTable") as Table).Width = new Unit("200px");
    ImageButton btnUploadFile = attrControl.FindControl("btnUploadFile") as ImageButton;
    AsyncPostBackTrigger newTrigger = new AsyncPostBackTrigger();
    newTrigger.ControlID = btnUploadFile.ID;
    newTrigger.EventName = "Click";
    IssueUpdatePanel.Triggers.Add(newTrigger);
}