Enable the button in user control

Source: Internet
Author: User

(this post is posted on the old blog of the version engineer on.)
User Control (User Control) can improve ASP.. net, especially in ASP. the usage rate in net 2.0 is higher than that in the past ASP. net 1.x is higher. A few days ago, when a project was created, you need to put "Save, add, modify" and other imagebutton in user control so that the pages can be dragged and referenced repeatedly. However, after you press "Storage" imagebutton in user control to send the verification control and JavaScript and regular expressions on each page, requests that have not completed verification cannot be blocked by default; that is, even if the data entered by the user is illegal or not entered, the verification control will still be sent to the backend server for processing even if it is caught with an error. Therefore, the version engineer makes some judgments in the Code On the page background, and opens this function to "delegate) "And the button-Click Event (raise event), C #2.0 example download of the anonymous method (using C #/asp. NET 2.0 ).

 
Figure 1 sample execution screen of ASP. NET 2.0 in this post
 
 
Note that the syntax of Delegate and event raising on the page is not the same in VB. NET and C. When VB. NET creates an event in user control, VB compiler automatically creates a delegate to "handle event". In contrast, C # requiresProgramThe user creates the delegate by himself. However, when the user control page is referenced, the user will respond to or process the triggered event (such as mmessage In the example downloaded by this post. showmsg (this. page, message);), VB. net requires programmers to write their own event processing routines, while C # provides the "anonymous Method" in version 2.0 to process events, as shown in the following syntax:

 

// Eventobject. someevent + = delegate (){
// Perform some custom processing in this block, such as the verification and storage work in the example of downloading this post.
// };

// Create a handler for a "sendmessage1" event in user control
// C #2.0 unique "anonymous method", which can take the entire {};
// All codes in the braces block are passed as parameters.
Ucauthbtnnew1.sendmessage1 + =   Delegate ( String Message) {
Page. Validate ();

If(Page. isvalid){
//Click "add, store, modify" or "exclusive actions" on each page.
}
} ;

-------------------------------------------
sample source code download point of this post:
http://files.cnblogs.com/WizardWu/070725.zip
(execute this example, do not use a database)

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.