简体   繁体   中英

aspx.cs cannot recognize the file upload

This is my .aspx file

<div>
<asp:Label ID="Label2" runat="server" Text="Interested? Apply Now!" Font-Bold="True" ForeColor="Red"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Upload Resume" OnClick="Button1_Click"/>
</div>

This is the .aspx.cs

protected void Button1_Click(object sender, EventArgs e){
    FileUpload1.SaveAs(Request.MapPath("//") + "resume//" + FileUpload1.FileName);
}

error

Error 1 The name 'FileUpload1' does not exist in the current context C:\\Users\\liezel\\Documents\\Visual Studio 2013\\WebSites\\WebSite5\\JobHunterProfile.aspx.cs 38 9 WebSite5(1)

If FileUpload1 is in a template (like in the Repeater.ItemTemplate or some other templated control), you can't refer to it directly, but only through FindControl. If it's a part of the normal page set of controls, yes it should work. Check your designer.cs file to see if it's there; you can always add it if it is missing... You don't usually have to do that, but I've had VS glitch and those control definitions get lost.

If you add it and get an exception, it's not supposed to be directly accessible and we would need to understand more of your code to figure it out.

Check this out

protected void Button1_Click(object sender, EventArgs e) {

string Path = Server.MapPath("/resume/" + FileUpload1.FileName);
FileUpload1.SaveAs(Path);

}

It will work and it is in Repeater controls then let me know ill send u another coede example

Please check if your DataList1 Bind on Page load event then Find control not work for this you have to bind dataList on pageLoad complete event like this..
protected void Page_LoadComplete(object sender, EventArgs e) { //Bind Your DataList or Repeater }

remove bind method from pageload event and check it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM