在asp.net中使用UpdatePanel控件的图像控件中出现NullException错误

时间:2014-03-26 05:25:02

标签: asp.net updatepanel

当我在asp.net中使用带有updatepanel的图像控件时,编译器会给出一个错误:NullReference异常,
请任何身体帮助我。那么应该做些什么来避免这样的问题?

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <ContentTemplate>
    <div>
      <asp:AsyncFileUpload ID="flduserphoto" runat="server"
                    OnClientUploadComplete="OnClientAsyncFileUploadComplete"
                    OnUploadedComplete="OnAsyncFileUploadComplete" Width="374px" />
                    <asp:Image runat="server" ID="imgPhoto" Width="150px" />
    </div>
  </ContentTemplate>
</UpdatePanel>

代码文件是,

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

DataTable dt;

#region FileUploadControl Section
protected void OnAsyncFileUploadComplete(object sender, AsyncFileUploadEventArgs e)
{
    if (flduserphoto.FileBytes != null)
    {
        lblgender.Text = "asdf";
        Context.Session.Add("SessionImage", flduserphoto.FileBytes);
    }
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
}

protected void btnSave_Click(object sender, EventArgs e)
{
    BALUserAddress objUserAddress = new BALUserAddress();
    objUserAddress.UserType = ddlusertype.Text;
    byte[]imageByte = new byte[flduserphoto.PostedFile.ContentLength];
    objUserAddress.ProfilePicture=imageByte;
    objUserAddress.ParentID = "0";
    objUserAddress.RelationWith="Self";
    objUserAddress.RegistrationDateTime= DateTime.Now;
    string msg = objUserAddress.SaveUserDetails();
    lblMsg.Text=msg;
    mpMsg.Show();
}
}

这是我的代码文件,请检查

1 个答案:

答案 0 :(得分:0)

在表单标记

中尝试这个

<form id="form1" enctype="multipart/form-data" method="post" runat="server">