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.