为什么MyFile上传在Autopostback期间没有包含文件 [英] Why MyFile Upload Has Not containg file during Autopostback
本文介绍了为什么MyFile上传在Autopostback期间没有包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用此代码上传图像并更新它,但我发现在Autopostback期间我的fileupload不包含图像,有没有任何解决方案。
I use this code for Upload a Image and also for update it,But i found that During Autopostback my fileupload doesn't contain image,Is there any solution for that.
<div class="form-group">
<asp:Label for="inputEmail1" class="col-md-2 control-label" ID="lblimage"
meta:resourcekey="lblBannerSignUp" Text="Image" runat="server"></asp:Label>
<div class="col-md-3">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="conditional">
<Triggers>
<asp:PostBackTrigger ControlID="btnSubmit" />
</Triggers>
<ContentTemplate>
<asp:FileUpload ID="fuimage" runat="server" meta:resourcekey="fuimage123" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="col-md-10 pull-right">
<img id="imagezoom" runat="server" />
<%-- <asp:Image ID="imagezoom" runat="server" />--%>
<%-- <asp:PlaceHolder ID="pnll" runat="Server"></asp:PlaceHolder >--%>
</div>
</div>
.cs文件代码
code for .cs file
EventManager_SuperAdmin m;
protected void Page_Load(object sender, EventArgs e)
{
m = (EventManager_SuperAdmin)Page.Master;
if (Session["FileUpload1"] == null && fuimage.HasFile)
{
Session["FileUpload1"] = fuimage;
}
else if (Session["FileUpload1"] != null && (!fuimage.HasFile))
{
fuimage = (FileUpload)Session["FileUpload1"];
}
else if (fuimage.HasFile)
{
Session["FileUpload1"] = fuimage;
}
if (Session["name"] == null)
{
Response.Redirect("~/SuperAdmin/Default.aspx");
}
if (!this.IsPostBack)
{
m.bussinesCollection.IDSecurity.Decrypt(Request.QueryString["id"]);
if (Request.QueryString["id"] != null)
{
var result1 = m.bussinesCollection.FeaturesBL.GetFeatureByFeatureID(Convert.ToInt32(m.bussinesCollection.IDSecurity.Decrypt(Request.QueryString["id"])));
txttitle.Text = result1.Title;
CKEditor1.Text = result1.Text;
fuimage.Attributes.Add("FileName", result1.Image);
imagezoom.Src = "/SuperAdmin/Images/" + result1.Image;
if (result1.Show_at_home == "Yes")
{
Chckshowfeatures.Checked = true;
}
else
{
Chckshowfeatures.Checked = false;
}
}
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Request.QueryString["id"] != null)
{
string image = fuimage.FileName;
if (fuimage.HasFile)
{
string Extention = System.IO.Path.GetExtension(fuimage.FileName);
if (Extention.ToLower() == ".jpg" || Extention.ToLower() == ".jpeg" || Extention.ToLower() == ".bmp" || Extention.ToLower() == ".png" || Extention.ToLower() == ".gif")
{
var path = Server.MapPath("Images/" + fuimage.FileName);
fuimage.SaveAs(path);
}
}
if (Chckshowfeatures.Checked == true)
{
m.bussinesCollection.FeaturesBL.Show_at_home = "Yes";
}
else
{
m.bussinesCollection.FeaturesBL.Show_at_home = "False";
}
m.bussinesCollection.FeaturesBL.UpdateFeatures(Convert.ToInt32(m.bussinesCollection.IDSecurity.Decrypt(Request.QueryString["id"])), txttitle.Text, CKEditor1.Text,image, m.bussinesCollection.FeaturesBL.Show_at_home);
lblmsg.Visible = true;
// lblmsg.Text = "Records updated successfully.";
Response.Redirect("ListOfFeatures.aspx");
}
else
{
if (fuimage.HasFile)
{
string Extention = System.IO.Path.GetExtension(fuimage.FileName);
if (Extention.ToLower() == ".jpg" || Extention.ToLower() == ".jpeg" || Extention.ToLower() == ".bmp" || Extention.ToLower() == ".png" || Extention.ToLower() == ".gif")
{
var path = Server.MapPath("Images/" + fuimage.FileName);
fuimage.SaveAs(path);
// this.Session["fileuploadforupdate"] = fuimage;
}
}
m.bussinesCollection.FeaturesBL.Title = txttitle.Text;
m.bussinesCollection.FeaturesBL.Text = CKEditor1.Text;
// m.bussinesCollection.FeaturesBL.Image = "~/SuperAdmin/Images/"+fuimage.FileName;
m.bussinesCollection.FeaturesBL.Image =fuimage.FileName;
if (Chckshowfeatures.Checked == true)
{
m.bussinesCollection.FeaturesBL.Show_at_home = "Yes";
}
else
{
m.bussinesCollection.FeaturesBL.Show_at_home = "False";
}
m.bussinesCollection.FeaturesBL.Insert();
txttitle.Text = "";
CKEditor1.Text = "";
lblmsg.Visible = true;
// lblmsg.Text = "Records Inserted Successfully";
Response.Redirect("ListOfFeatures.aspx");
}
}
我也试试会话但它对我没有帮助。
如果还有其他解决方案吗?
提前致谢
I also try with session but it is not help me.
If there is any other solution ?
Thanks in advance.
推荐答案
在你的aspx中试试这个: -
try this in your aspx:-
<div class="col-md-3">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:FileUpload ID="fuimage" runat="server" meta:resourcekey="fuimage123" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>
</div>
这篇关于为什么MyFile上传在Autopostback期间没有包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文