Click here to Skip to main content
15,890,946 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
protected void Page_Load(object sender, EventArgs e)
        {
        HtmlInputFile filUpload = (HtmlInputFile)this.FindControl("filUpload");
        }


C#
protected void btnSave_Click(object sender, EventArgs e)
        {
        if (filUpload.PostedFile != null)
            {
            }
        }



<input id="filUpload" type="file" />


Im getting the error while checking the filUpload.PostedFile!=null...
Can u please help me..


Thanks in advance...
Posted
Comments
Er. Puneet Goel 9-Apr-14 3:33am    
are you using the same as you mentioned above or something else..! provide more details

The reason that you get the error is because the variable filUpload is null: the filUpload control could not be found, because you have not added runat="server" to it. Add runat="server":
HTML
<input id="filUpload" type="file" runat="server" />
 
Share this answer
 
v2
Check your names: If FindControl cannot find a control with that exact name, it will return null - this will cause your test to try and work with a null reference and the exception will be thrown.
 
Share this answer
 
The error was generated by the fact that your call FindControl("filUpload") did not find your upload control, so you are using a wrong control ID, and the result is a null object.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900