ASP.net 3.5 control and Component development Technology series-debugging techniques in server control development

Source: Internet
Author: User

Content of this chapter

2.1 Preset code example

2.2 Debug Page service-side code

2.3 Debugging of server controls

2.4 JavaScript Script Debugging method

2.5 Ajax Library support for JavaScript debugging

2.1 Preset code example

Readers who are familiar with asp.net development may be more open to debugging techniques for server controls, but it doesn't matter if you just touch asp.net, this chapter starts with the basics of debugging.

Before debugging, create a project environment in which to debug the control. about how to build the environment here is not to say, the 1th chapter has been very detailed.

First, add a main control code file DebugControl.cs in the Web Control Project project, and the following is the code for the main file DebugControl.cs of the sample code control in this chapter:

[ToolboxData("<{0}:DebugControl runat=server></ {0}:DebugControl>")]
/// <summary>
/// 获得本书更多内容,请看:
/// http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
/// </summary>
public class DebugControl : WebControl 
{
   Button btnDebugScript = new Button();
   protected override void CreateChildControls()
   {
     this.Controls.Add(btnDebugScript);
     base.CreateChildControls();
   }
   protected override void Render(HtmlTextWriter writer)
   {
     btnDebugScript.Text = "调试客户端脚本";
     btnDebugScript.OnClientClick = "ClientClickEvent();";
     btnDebugScript.RenderControl(writer);
   }
}

The code is simple, mainly generates a button, and registers a client click event clientclickevent for the button. CreateChildControls and render are some of the ways in which the custom control lifecycle phases are executed sequentially, as described in chapter 1th on the control lifecycle, and are explained in more detail in the next chapter. This chapter focuses on the technical part of the debugging of controls.

In addition, the implementation code of the method that the control client event executes is added to the

   <script language="javascript">
     function ClientClickEvent()
     {
       alert('我被单击了一下!');
     }
   </script>

Client Clientclickevent method Body on a word, pop-up a hint. View the Debugcontrol.aspx page in the browser. and click on the button on the page to run the effect as shown in Figure 2-1.

Figure 2-1 Control Run diagram

This sample code is very simple, but it has been able to show the content of all control development debugging. So far, the first step has been completed, and the next steps are to introduce the debugging content related to control development.

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.