这就是我的想法.. 我正在通过 FileUpload Control 上传图像..但是当我触发 updatepanel 时 Fileupload 控件显示它是空的..我不知道为什么..
这就是我需要的..
仅当我单击上传按钮时才需要更新我的更新面板,然后我不想更新其内容。我需要在编码中做哪些更改
这是aspx代码..
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"/>
<div>
<fieldset style="width:50%; margin-left:300px">
<legend>Upload Files</legend>
<asp:FileUpload runat="server" ID="UploadImages" style="background-color:white; position:relative; font-family:'Palatino Linotype'; font-size:medium" Width="500px" AllowMultiple="true"/>
<asp:Button runat="server" ID="uploadedFile" style="position:relative; font-family:'Palatino Linotype'; font-size:medium; width: 112px; height: 29px;" Text="Upload" OnClick="uploadFile_Click" />
</fieldset>
<div id="back" runat="server" class="transbox" style="width:100%;height:100%;left:0px;top:0px;position:absolute" Visible="false">
<asp:UpdatePanel ID="updtpanel" runat="server" UpdateMode="Conditional" style="width:100%;height:100%;left:0px;top:0px;position:absolute">
<ContentTemplate>
<asp:Button ID="btnsave" runat="server" UseSubmitBehavior="true" Text="Find Images" OnClick="btnsave_Click" Font-Bold="true" style="position:absolute" BackColor="Yellow"></asp:Button>--%>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="uploadedFile" EventName="Click"/>
</Triggers>
</asp:UpdatePanel>
</div>
</div>
</form>
这是 FileUpload 的 .cs 代码。
protected void uploadFile_Click(object sender, EventArgs e)
{
if (UploadImages.HasFiles)
{
string fileExt = Path.GetExtension(UploadImages.FileName).ToLower();
if (fileExt == ".jpeg" || fileExt == ".png" || fileExt == ".jpg" || fileExt == ".bmp")
{
foreach (HttpPostedFile uploadedFile in UploadImages.PostedFiles)
{
count1 += 1;
}
foreach(HttpPostedFile uploadedFile in UploadImages.PostedFiles)
{
count += 1;
filepath = Server.MapPath("~/Images/" + uploadedFile.FileName);
uploadedFile.SaveAs(filepath);
newpath = "../Images/" + uploadedFile.FileName;
try
{
createImgPanel();
Image nimg = Page.FindControl("img" + count) as Image;
nimg.ImageUrl = newpath.ToString();
Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('Files Uploaded!!');", true);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
else
{
Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('Please Select only Image Files!!');", true);
}
}
else
{
Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('Please Select a File First!!');", true);
}
}
如果我评论更新面板中的触发器uploadFile.HasImages
将起作用..但如果我取消评论它将直接登陆请先选择一个文件错误消息..在代码中犯了什么错误..