Usually this thing happens if you are using script manager and update panel in your page. While clicking the submit button or when a postback happens, your file upload's file vanishes and FileUpload1.HasFile always returns false. There are several ways to handle this.
Process-1 : Add a trigger to your Update Panel.
Please do send me comments if you like my posts. Your suggestions are most welcomed.
Process-1 : Add a trigger to your Update Panel.
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
Process-2 : If your page is having a Master Page and your update panel is present there in the master page,then you have to dynamically add a trigger to the master page's update panel from the child page.
public void AddTrigger()
{
PostBackTrigger trigger=new
PostBackTrigger();
trigger.ControlID=btn.UniqueID;
UpdatePanel updt = (UpdatePanel)this.Master.FindControl("UpdatePanel1");
updt.Triggers.Add(trigger);
}
Then, call this method in the Page_Load Event.
protected void Page_Load(object sender, EventArgs
e)
{
AddTrigger();
}
Process-3:
protected void Page_Load(object sender, EventArgs
e)
{
ScriptManager.GetCurrent(this).RegisterPostBackControl(btn);
}Please do send me comments if you like my posts. Your suggestions are most welcomed.
No comments:
Post a Comment