See, in real life, when you interact with some objects, you don't really care about the internal implementation or complexity of that object. For example, when you use your computer, all you care about is how to power on or off by switching the button, how to input data (Using keyboard or mouse) and as a user, you really don't care about how the computer is internally operating,taking your inputs and processing it to show output.
So, the computer has not exposed the internal complexities to you, or, to the outside world. All it provides is an "Interface" to the outside world with the information that the outside world needs to know to use and operate the computer. As a user, you are happy to know about the "Interface" only, rather then the Internal implementation and complexity (The "Class").
In the programming world also, when you need to develop a class (Which may do many complex things), you need to expose the capabilities and operation of the class to other applications or class libraries (That may use this class) so that they can understand and use your class accordingly. So, what you do is, you create an Interface that contains the method signatures and you implement those methods in your class. So, the client applications and libraries can develop their codes based upon the Interface you defined. While at runtime, the method invocation on the interface actually will turn out to method invocation in the implementation class.
Use of interface gives you extreme flexibility. For example, suppose you have an interface (IComputer) that exposes the functionality to the outside world and you have a class (WindowsPC) that implements the Interface method. Now, based upon some requirement, you can develop another class (MacPC) that implements the interface methods in a different way (Because, a MAC pc has the same kind of features, but, internally operates diffrently). Now, if the client application codes are developed based upon the Interface (And, not based upon the implementation classes), there is very little chance that, they would need to change their code. Why? Because, both of your implementation classes actually implements the same interface.
For example, WindowsPC and MacPC both implements the IComputer interface. So, if your client codes are developed using the IComputer interface and they accept the IComputer interface as parameters in their methods, you can send them an MacPC object, instead of the WindowsPC object any time and the client code will run perfectly without any problem (As long as your implementation classes are implemented correctly).
So, use of Interface gives you flexibility to your code that you can manage easily and you can extend it without much change.
Basically, use if interface is part of the basic Object Oriented Principles. You may take a look at this article How I explained OOD to my wife[^] to learn these principles.
I marked it as a good answer but I think people asking these questions should do a Search for the same. These things are already explained at so many places. So if you do a search and read some articles/posts you will have a complete understanding of the topic. Just my opinion.
The Server.MapPath() actually returns the physical location of a file based upon a relative path provided to it. So, while saving the image, use of Server.MapPath() is the correct way to obtain the physical path for saving the file.
But, while you have to display the file in the <asp:Image> server control, you should assign a relative URL of the image to the Image1.ImageUrl property. Assuming that, you are storing the image under the "/hint" folder (Inside your web application root folder), you should write the following code for displaying the image:
How can I read data from ListView into my List list?
The operation of reading ListView data into List generic list should begin after clicking the button "GetData".
I saw the following advice:
List<MyClass> list = ListView1.Items
.Select(lvi=>lvi.DataItem as MyClass)
but it does not work - the DataItem property of each Item of ListView has null value.
The point is that I have generic list with data. I am binding this data into ListView which can be edited by user. After that after click Save or GetData data from ListView is read into generic list of MyClass type.
i have got 3 text boxes in my content page. on the press of enter key in textBox1 focus should be on textBox2 and there on press of enter key focus should be on textBox3. after pressing enter key there, button click event should be called.
please help me with some code
If you understand Static class concept properly, then you will automatically come to know which method best suits your requirement. If the class is not specific to a particular instance or otherwise if you want some logic shared among all the users then you can go for static classes.
Does anyone know where I can find examples and/or explanations on how to implement Structure Maps/Dependency Injection in C#? I have tried finding examples on the Internet, but what I found was not very good.
Are you assigning the value of the checkbox outside of an if(!IsPostBack) statement? If so your view state value is being wiped. If you are using DataBinding, make sure your DataBind call is wrapped inside of an if(!IsPostBack) as well.
Please ensure that to put IsPostback condition in page load event.when u call button click event, it'll be postback to the same page and page load then button click events fires. so check it and keep the condition.
In my website there is facility that user can send mail using it own email SMTP setting. some user is sending mail success fully but some facing problem for this there is option in config page in which user have to enter his SMTP setting. And also there is test button when users press a test button and if any wrong entry (username, password, smtpServer) then I want to show pop message accordingly.
Is any way in which we can identified that what is wrong entry (username, password or mail server) because I want to give message like "wrong username or wrong SMTP server?
There isn't really anyway to check. For instance, in a hosting environment two SMTP servers could be 10.54.16.10 and 10.54.16.20. If they enter the former when they should using the latter, how can tell the difference? It is a valid address, just the not the correct one for them.
If you give wrong server entry, however It'll give an error like "Relay access denied on 5.7.xx" like that and if u give a wrong credentials it'll throw an error like "Could not connect to the host...". From these errors you can show your custom message to the user. I hope u understand it .
firstly, sorry if I post it for 2nd times. because its a week I stuck in this problem
I am trying to build up my knowledge regarding ASP.Net and new things which I read from books. Frankly, its few days I got this error. after running my code I see this error No matching bindings are available, and the type is not self-bindable. Activation path: 2) Injection of dependency CommunityUserRepository into parameter _rep of constructor of type AccountController 1) Request for AccountController
it is the source code
publicclass NinjectControllerFactory : DefaultControllerFactory
// A Ninject "kernel" is the thing that can supply object instances
private IKernel Kernel = new StandardKernel(new SportsStoreServices());
// ASP.NET MVC calls this to get the controller for each request
protectedoverride IController GetControllerInstance(RequestContext context,Type controllerType)
//if (controllerType == null)
// return null;
return controllerType == null ? null
// Configures how abstract service types are mapped to concrete implementations
privateclass SportsStoreServices : StandardModule
//registered any IProductsRepository with the DI container.
error occure in this line protected override IController GetControllerInstance(RequestContext context,Type controllerType)
//if (controllerType == null)
// return null;
return controllerType == null ? null
Could you please help me?
Hi there, i'm no ninject expert im afraid - only did one mvp-windows-mobile project with it -
so this may not be an answer..
..but obviously, the ninject kernel cannot inject CommunityUserRepository while creating the
controller instance. This usually means that no corresponding mapping has been loaded into the
kernel inside "Load". So maybe, you have to include a mapping for CommunityUserRepository in the kernels load-method. Also, the constructor parameter "xyRepository" of your controller should maybe
be an interface.
(There may be other places for ninject interface/implementation bindings, i dont know..)
If you add a "Modifydate" column to your table, then each time you update a row in the table, set the ModifyDate to the CurrentDate-Time. You can then issue a select max(ModifyDate) on that table to display the latest update date on your web page.
I m new in Ajax and asp.Net Now i want learn ajax with asp . In My Visual studio 2008 , there is no option is Ajax Wizard . If need any thing install for Ajax , please let me know the URL . And Give simple idea for How can make simple application ...
"My personality is not represented by my hometown."
the hex information i pasted containing the image information.
can anybdy help me to convert this hex to image.Pls pls help me.I am trying to do this from the last few weeks.pls share me ur ideas.i converted this to binary and tried to open it .but picture is showing with a cross icon.Pls give me some code for this.