Who is the loaner? Whether he is a father or a son, just pay back the money.

Source: Internet
Author: User
Tags money back

Who is the loaner? Whether he is a father or a son, just pay back the money.

This article starts from the case, in order to better understand the interface and C # knowledge, aside from the client jQuery or Javascript knowledge, that is, ASP. NET and C # are discussed together.

Before entering, you can first read the msdn article "Cross-Page Posting in ASP. NET Web Pages" http://msdn.microsoft.com/en-us/library/ms178139 (v = vs.110). aspx or the previous Forum question

Why does my cross-page transfer always report an error! Object not instantiated? Http://bbs.csdn.net/topics/390937410. Both articles can be classified into the same type of knowledge. However, they share a common place, that is, to specify the name of the control in the previous page on the target page, and the red arrow points to the highlighted position:


This is the focus of this discussion, that is, you cannot write it to death. For example, if you (the borrower) have a lot of money, lend it to a lot of people (the lender), and you are not sure about the number of people, now you remind or they want to pay you back. Therefore, the borrower cannot only use TextBox1 to represent all lenders.
The credit may be TextBox2, DropDownList3, RadioButtonList2, ......

In this way, you have to write a lot of code in the above MSDN code example, such:


Now, how do we solve this problem, and how do we know who pays back.

To understand this problem, Insus. NET creates an asp.net site and several web pages by the way (Debit) Loan (Credit).

The following shows the program of the demo site. The first is the Debit. aspx:

 

Debit. aspx. cs:

 

The following is Credit. Insus. NET, which lists four items in the demo. There may be a few in the actual environment. Credit1.aspx:

 

Because Creditn. aspx. cs does not write any code, it will not be posted.
Credit2.aspx:

 

Credit3.aspx:


Credit4.aspx:

 

The program runs properly:



The above programs are all written to death. If we change them a little bit, it will be faulty. Next, let's take a look at other problems:


During system maintenance on one day. aspx changes some controls, so it cannot get the value, or it is in Debit. aspx. the code in cs changes the Control ID. In these cases, the Control ID must be changed in several places during development or maintenance. Once the value cannot be obtained, you need to re-debug the program.

OK. We need to solve these problems. First, the code can be constantly increased. Another problem is that we don't want to write the Control ID.

In fact, the final concern is whether the lender has returned the money. Therefore, we can create an Interface:



The interface is written, and the lender needs to implement this interface, because the loan will be paid back after the loan is made.

Let's take a look at Credit1.aspx. cs:



Credit2.aspx. cs:


Credit3.aspx. cs:


Credit4.aspx. cs:


Anyone who has borrowed money must implement this interface.

This is easy to do:


After this change, the program has been split. One Party only needs to get his money back, and the other party, whether his father or son, pays back the money (TextBox1 or DropDownList3 ......)

The running result is the same as that before reconstruction.

If a Credit party has any changes, if TextBox1 is changed to TextBox9 or DropDownList2 to TextBox, it is irrelevant to the Debit borrower. For example, Credit3.aspx:



You only need to modify Credit3.aspx. cs:



All said. Although it is a simple example, I hope you can better understand the application of interfaces in asp.net. To be honest, there are often examples of using interfaces in Insus. NET blogs. If you have time, you can refer to them for better understanding and understanding:
Http://www.cnblogs.com/insus/category/308317.html


This demo source program can be downloaded at the following link:
Http://download.cnblogs.com/insus/ASPDOTNET/DebitAndCredit.rar

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.