Why is Visual Studio saying my member is defined more than once?

Hi, I copied this from a tutorial but now its saying that my member or variable is defined more than once.  I guess I don't see it.  Can someone else point out where its defined more than once?
undefined.png
add.aspx.cs
FairyBusinessAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dimajCommented:
I'm guessing it is referring to the FileInput, right?

You class is partial, which means that it has been split up into 2 files with the same class name 'upload'. Find the other file and see if FileInput has been defined there.
0
FairyBusinessAuthor Commented:
No I dont have this class split up or defined any place else. I just copied it from a tutorial.  And yes its referring to the FileInput
0
ddayx10Commented:
Its telling you its a duplicate because it is.

You have assigned a control on the aspx side and given it an id of fileInput then you have created a global "protected" variable named fileInput. You can't have two objects with the same name in scope at the same time...its a duplicate.

Change the name of one of the objects. Either you aren't following the tutuorial exactly or it is a flawed tutorial.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

dimajCommented:
add.aspx.cs and add.aspx are partial classes. Class "add.aspx.cs" continues "add.aspx". See if there are any references to FileInput there.
0
FairyBusinessAuthor Commented:
oh, well yeah I have an id of FileInput but I thought it had to have the same name so that it knew what form field it was receiving the file from

http://www.java2s.com/Code/ASP/Components/FileUploadDemoC.htm
add.aspx
0
dimajCommented:
What type is the "INPUT" field in your aspx file? What will happen if you will comment out declaration of FileInput in add.aspx.cs file?
0
ddayx10Commented:
Technically you do have the class "split up" pages are declared as partial commonly because the aspx and aspx.cs files are one class that is broken up so you have an aspx page and a code-behind. When compiled these two "partials" become one class.

Anything declared on the front end is a part of the back end. You already likely understood this to an extent but that may help you to understand better.
0
ddayx10Commented:
Now see that tutuorial is a good point of learning for you. That tutorial is not using a "partial" class. It is using the single page/class method.

When you create a new page in VS notice there is a checkbox to "place code in seperate file". If you have that checked then VS creates a front/back and uses a partial class model. If you dont check that then you get a single page/class mode.

If you want to use that tutorial create a new page without the code behind.

If you want to learn how to upload files then that may not be the best tutorial for you, its a bit dated.
0
ddayx10Commented:
This is still kinda old, but that is good for learning the basics. It may be easier for you to follow and get through more quickly.

http://asp.net-tutorials.com/controls/file-upload-control/

This uses the same partial page model that you started with. Its nice and short and quick and I believe (at a glance) it does everything your first sample does.
0
FairyBusinessAuthor Commented:
@ddayx10 yes I think that is a better tutorial.

I take it I should not use a partial class?  When should I choose to use partial classes?
0
ddayx10Commented:
No use the partial is fine. You just needed that information for future reference so when you see  code like the sample you had you understand what you're looking at.

I suggest you use the seperate code file (partial class) always. It should be much easier for you to learn from and you will find it most common in sample code you run accross.
0
dimajCommented:
0
FairyBusinessAuthor Commented:
ok, but how do I get rid of the red underlining that is still in my code??
undefined.png
0
käµfm³d 👽Commented:
@ddayx10
Technically you do have the class "split up" pages are declared as partial commonly because the aspx and aspx.cs files are one class that is broken up so you have an aspx page and a code-behind. When compiled these two "partials" become one class.
That's not entirely accurate. The "split up" classes are found in the .aspx.designer.cs and aspx.cs files; the markup page inherits the class defined in the code-behind file (typically aspx.cs). This is why you can access protected members, but not private members within the markup page.

The two partial classes are found in the two xxx.cs files (if they exist).
0
dimajCommented:
I'm just starting to guess here (as I've never done asp before)...

What will happen if you will put the field declaration back into the cs file and modify "id" values in your aspx file.

I'm guessing that field types are different and you're trying to access property Accept which is not present in the INPUT type.
0
FairyBusinessAuthor Commented:
@dimaj

I don't really understand what you are saying.

What will happen if you will put the field declaration back into the cs file and modify "id" values in your aspx file.

I don't understand why I would do that?  I need to be able to access the field Id so why would I change the id to access something that's not there anymore?  

I just want to know why the .Accept and .PostedFile are get the red underlining now. . .
0
dimajCommented:
This is just a guess...
Because type of INPUT is not HtmlInputFile. While HtmlInputFile has a property called Accept, INPUT does not have it.

Does this make sense?
0
käµfm³d 👽Commented:
When should I choose to use partial classes?
You have a prime example before you. But let's ignore that one for the moment. Let's talk about Win forms.

When you create a forms application, you get a designer file (the file that holds all the definitions of the controls you placed on the form), and you get a regular code-behind file (sounds a little like the ASP stuff, huh?). Why would Microsoft make this such a "burden"? Think about it like this, every time you move a control, add a control, resize a control, those modifications have to be stored somewhere, otherwise, when you compile the code, none of the settings you made will be apparent during runtime. The designer rewrites the designer file every time you make a change on the designer.

Since the designer always overwrites the designer file (where the controls are defined), what would happen if you also included business logic in this file as well? You would lose your business logic every time you made a change in the visual designer!! If you separate your business logic (which shouldn't change, much) from the controls definitions (which may very well change as you rearrange, resize, remove your controls), then you maintain the part of your code that shouldn't change from the more dynamic parts of your design.

Back to ASP...

Pretty much the same thing happens in ASP.NET (web applications, not web sites, usually):  you get a designer file which holds the definitions of the controls you added to the designer (the markup file) and you get code-behind file where you business logic goes. As you move controls around your web form, the business logic isn't affected by these changes.

In short, you use partial classes whenever you have two parts of your code where one part may change quite a bit, and you have another part that doesn't change all that much.

Another instance where you might use partial classes is when you have two developers working on the same class. You might delegate each developer work on two different aspects of the class.
0
ddayx10Commented:
@kaufmed :) thanks.

I was simply trying to explain it so a beginner can understand what is happening and where they went wrong. I'm not writing the manual or trying to teach perfect asp.net concepts.

I'm not sure I entirely understood the distinction you were trying to make there and I'm sure the user didnt. I've seen the evidence (beyond your staggering point total) of your acumen in this area and appreciate when you help out.


@FairyBusiness

>>ok, but how do I get rid of the red underlining that is still in my code?? <<

Alas its because you removed the protected global variable and because the type <input> you are using on the front end doesn't have an "Accept" property inherantly.


I'm sorry @FairyBusiness but you are making life harder for yourself. You need to either:

A) Make the page again without the partial class code-behind (single file) and copy paste the sample over again.

OR

B) Start again with the 2nd sample I gave you.

Sometimes its also good to "see" things done and you can pickup a few tips and tricks along the way. You may want to view this:

Video:
http://www.asp.net/web-forms/videos/how-do-i/how-do-i-simple-file-uploads-in-aspnet
0
FairyBusinessAuthor Commented:

@dimaj I guess it kind of makes sense....  I just need to know how I can make these right in my code

@kaufmed I'm not working on a web application though, I'm working an a website.  Does that make a big difference?  Where do I find my designer files at?
0
dimajCommented:
change the id value to something else and place your field declarations back into your code. See what happens...
0
ddayx10Commented:
Ok after reading a little of your post I see the distinction. I think I've said everything about the initial problem and some help to learn about using the upload control...

I hope it all helps you @FairyBusiness.
0
käµfm³d 👽Commented:
@ddayx10

I make the distinction because saying the designer (markup file) and code-behind files are both partial classes implies that the markup would have access to all members defined by the code-behind (including the private members). This is not the case, and implying that it is could cause confusion in the future.

That said, the link I am posting in the next comment may actually veto what I said anyway. Perhaps what I mentioned earlier only applies to web applications, because I myself haven't been able to refer to private members in the markup file. I've always had to declare them as protected in order to reference such members in the markup file.

@FairyBusiness

I think you will need the partial keyword in this instance. This is based on what I found here.
0
ddayx10Commented:
@kaufmed. Appreciated.

Really just needed @FairyBusiness to understand 2 files vs 1 file and how to setup samples when seen.

FairyBusiness is admittedly just winging it and trying things. I'm pretty sure your point will be cool, but too advanced to make an impact on this question.
0
FairyBusinessAuthor Commented:
@dimaj  Maybe I don't understand what field declarations are but it just doesn't make sense to me to change their names. I changed them and the red underlining went away, but it just makes no sense to me so I don't want to do it.  How can it access something it doesn't have the correct name for?  I don't like this at all.  Now it just seems random and abstract to me.

@ddayx10  I guess you could call it "winging it and trying things".  I am trying to learn and what's worked for me in the past (when it comes to web languages) is just going off of tutorials and trying to learn as I go.
0
ddayx10Commented:
Well I based my phrase off post 37318061. Seemed like "winging it and trying things" fit. Nothing wrong with winging it and trying things if your learning.

Given that you were having trouble trying to setup the sample from a single page aspx file using a different model (code behind). It seemed better to follow one model or another, not try to make a hybrid of the sample.

Honestly I'm not sure what else to say. Feel kinda bad for you when you get pulled 3 different directions. Hopefully you understand better what's up and got something out of all of that.

Your original question was "why does it say I have a duplicate?". Asked and answered.
 
Tried to show a little more why that was going sideways for you. Tried to show you how to do it properly with the example you had and 2 new examples.

s'about all that can be done.
0
FairyBusinessAuthor Commented:
Yeah, I guess my question has been answered, I just hadn't realized it because I still feel confused and not sure which direction to take at this point, but "I'll wing it"
0
käµfm³d 👽Commented:
Just make sure you add a "Web Form" whenever you do "Add New Item..." and you'll negate some of the issues you've experienced thus far (including previous questiond)    = )
0
FairyBusinessAuthor Commented:
will do!  :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.