????? ???????? vs. ?????????? ???????? ?? ????????? ??????

???? ?????? ???? ??????
???? ID: 893667 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
ASP.NET ?????? ???? ?????

????? ???????? vs. ?????????? ???????? ?? ????????? ??????

???? ?????????? ?? ??? ?? ????? ?? ???????? ???? ?? ??? ?? ???? ???? ??? ?? ?? ???????? ?? ????? ?? ??? ????? ??? ?? interest ?????? ?? ???? ??? ???????? ?????? ?? ?????? ???? ????? ?????? ??? ??????? ????? ???? ?? ??? ?? ???????? ???? ????? ??? ???? ???? ?? ??????????? ?? ????? ???? ??? ????? ?? ???? ?????? ?? ??? ????????????? ?? ????? ?? ???? ??????? ?? ??? ?? ???? ?? ???
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

?????

Hi! ?? Parag ??, ?? ?? ?????? ???????? ?? ?? ???? ???? ?? ??? Microsoft asp.NET ?????? ???? ??? ??? ??? ?? ??? ???? Microsoft ????????, ???? ?? ???? ??? ????????? ???-?????? ?? Microsoft ??????? ?? ????? ?? ???????? ????????? ?? ??? ???? ??? ???????? ?? ??? ???????? ?????? ?????? ??, ???? ??? ??? ?????? ???? ????? ???????? ?? ??-??? ??? confusion ??, ?? ??? ??? ???? ??????? ????? ???????? ?? ??-??? ??? ????????? ?? ?????? ?? ??? ??? ??? ?? ???? ??? ??? ?? ??? ??? ???? ?? ????? ??, ????? ????, ?? ?? ???? ????? ???, ?? ??? ?? ?? ???? appreciate asp.NET ???? ?? ??? ????? ?????? ??? ?? ??????

????????? ??????

?? ????? ????? ???, ??? ????? ???? ?? ????? ????:
  • ???? ?????????? ???????? ????
  • ???? ????? ???????? ????
  • ???? ?????????? ???????? ?? ????? ???????? ?? ??? ??? ???? ????
??? ?? ????? ????????, ???? ?? ?????? ?? ??????? ?? ????? ???????? ?? ???????? concern ????? ?????? ?? ?? few introduce ?????

???? ?????????? ???????? ????

?????????? ???????? ???, reusable ????? ????????, ?? ?? HTML ?? ??? ????? ???????? ?????? employed ???? ??????? ?? ????? ????? ?? ???????? ?? ??????? ?????????? ??????? asp.NET ??? ????????? ?? ???: ????? ???? ?? ??? ?? ???? ????? ?? ???????? ???? ??? ?? ??? ??? ??????? ???????????? ???? ??? ?? ??? ??? ??????? ????? ??? ?? ????? ????? ???? ???????????? ??? ??????? ?? ???? ??? ???? ??????? ?? ??? ????? Microsoft ?????? ??????? (MSDN) ??? ?????? ?? ????:
??????? ?? ??? ??? ?? ??? ?????
(vs.71) http://msdn2.Microsoft.com/en-us/library/65tcbxz3 .aspx

??? ??????? ??? ????
(vs.71) http://msdn2.Microsoft.com/en-us/library/015103yb .aspx

???? ?????????? ???????? ????? ?? ??? ???? ????

???? ?????????? ???????? ????? ?? ??? ????? ???????? ???????? ??? ??????? ????? (.aspx) ????? ?? ??? ????? ???? ?? ??? ???? ??? ???? ???? ?? ?? ???? ?????????? ???????? ????? ???? ??<html>,<body> , ??<form>???? ????? ???? ??????? ?? ??? ??? ?? ?????????? ???????? ????? ???? ???????? ?? ??? ??? ?????????? ????????, ?? ????? ?? ???? ????:</body></html>
  1. ??? ?? HTML ?????? ?? ?????, ?? ??? ???, ???????, ?? ??????? exposing ?????-???? ??? ??? ??????
    <script language="C#" runat="server">
       public void button1_Click(object sender, EventArgs e)
       {
          label1.Text = "Hello World!!!";
       }
    </script>
    
  2. ?????????? ???????? ?? ??? ??? ?????????? ???????? ??????
    <asp:Label id="label1" runat="server"/>
     <br><br>
    <asp:button id="button1" text="Hit" OnClick="button1_Click" runat="server" />
    

???? ??????? ?? ??? ??? ??? ?? ?????????? ???????? ?? ????? ???? ????

  1. Microsoft Visual Studio .NET 2002, Microsoft Visual Studio .NET 2003, Microsoft Visual Studio 2005, ?? ???? ??? ?????? ??? ?? ?? ??? ??????? ????? (.aspx) ?? ??????
  2. ?????@ ???????directive. ?????? ?? ???, ????? ??? ?? ????? ?????
    <%@ Register TagPrefix="UC" TagName="TestControl" Src="test.ascx" %>
    ???:???? ?? ?????????? ???????? ?? ??? ??????? ??? ?? ?? ?? ????? ?? ????
  3. ??????? ?? ??? ??? ??? ?????????? ???????? ?? ????? ????, ??? ??? ????? ??? ?? ????? ????@ ???????directive.
    <html>
        <body>
              <form runat="server">
                   <UC:TestControl id="Test1" runat="server"/>
              </form>
        </body>  
    </html>
    

???? ?? ???? ??????? ?? ??? ??? ?? ???? ??? ??? ??? ?????????? ???????? ?? ??????? ?? ????????? ????? ?? ??? ???? ????

????? ?????? ?????????? ???????? ?? ?? ??? ??????? ????? ????? ??? declaratively ???? ????@ ???????directive. ???????, ?? ?? ???? ??? ?????? ??? ?? ?? ?????????? ???????? ?? instantiate ?? ????? ??? ?????? ???? ?? ???? ?? ??? ??? ???:
  1. ??? ??? ??????? ????? ?? Visual Studio ??? ??????
  2. ??? ?? ?? ??? ?? ??? ??? ?? ??? ????? ????? ?? ???? ??????? ?????
  3. ?????Page_Load?? ?????????????? ???, ????? ??? ??????
    // Load the control by calling LoadControl on the page class.
    Control c1 = LoadControl("test.ascx");
                
    // Add the loaded control in the page controls collection.	
    Page.Controls.Add(c1);
    
    ???:?? ??? ???? ??? ??? ?????????? ???????? ?????? ??? ?? ????? ???? ???? ?? ??? ?????? ???

    ???? ??????? ?? ???, ????? ??? ?????? ?? ????:
    ????????? ?????? ???? ??????? ?? ??? ??? ?? ??? ???????? ??????
    (vs.71) http://msdn2.Microsoft.com/en-us/library/kyt0fzt1 .aspx

    ???????? ???????? lifecycle
    (vs.71) http://msdn2.Microsoft.com/en-us/library/aa719775 .aspx

    ???????? ??? ????????, postbacks ?? ????? ??????, Scott Mitchell ??????
    HTTP://aspnet.4guysfromrolla.com/articles/092904-1.aspx

???? ?????????? ?? ???????? ???? ??????? ??

?? ??? ?????????? ???????? ?? ??? ?? ????? ?? ?????? ???? ??, ?? ????? ???? ??:
  • ????? ?????? ?????? .ascx ????? ??? ????????? ????Src??? ???????@ ???????directive ?? ?? ???? ?? derives ?? ????? ??System.Web.UI.UserControl?????
  • ?????? ?? ?????? ??? ?? compiles ???? ?? ??????? ????
  • ??? ?? Visual Studio ?? ????? ?? ??? ???, ?? ??????? ??? ??? ????, Visual Studio ????? ?????????? ???????? ?? ??? ????? ?? ???? ??? ???, ?? precompiled designer ????? ?? ?????? ????? ???
  • ???, ???? ?? ?????????? ????????, ?? ???????? ??? ????? ?? compilation ?? ????????? ?? ????? ??, ?? ??? ????? ?? ???? ??? ?? ??? ??? ????? (. ascx.cs) .ascx ????? ?? ???? ???? ??? ?? ??? ???

???? ????? ???????? ????

????? ???????? ?? ????? ?? ???????? ???????? ???? ??????? ????, ?? ??????? ???, HTML ?? XML, ???? ????? ?????? ??? ??? ???? ??? ???? ??????? ??? ??????? ?? ?????????? ???????? ???? ???

???? ????? ???????? ?? ??? ???? ???? ?? ????? ?? ??? ???? ????

??? ????? ???????? ?????, ???? ????? ???? ?? indirectly derive ?? ??? ????System.Web.UI.Control???? ?? ??System.Web.UI.WebControls.WebControl????:
  • ?? derive ?????System.Web.UI.Control??? ?? ???????? nonvisual ?????? ?? ????? ???? ?? ??? ????? ???? ?????? ?? ???, <meta>??<head>nonvisual ???????? ?? ?????? ????</head>
  • ?? derive ?????System.Web.UI.WebControls.WebControl??? HTML ????? ???? ?? ??? ???????? ???? ????? ??? ?? ??????? ???????? ?? ??? ????? ??????? ????? ???
If you want to change the functionality of existing controls, such as a button or label, you can directly derive the new class with these existing classes and can change their default behavior.

In brief, the????????class provides the basic functionality by which you can place it in the control tree for aPage????? TheWebControlclass adds the functionality to the base????????class for displaying visual content on the client computer. For example, you can use theWebControlclass to control the look and styles through properties like font, color, and height.

How to create and use a simple custom control that extends from System.Web.UI.Control using Visual Studio

  1. Visual Studio ??????? ?????
  2. Create a class library project, and give it a name, for example, CustomServerControlsLib.
  3. Add a source file to the project, for example, SimpleServerControl.cs.
  4. Include the reference of theSystem.Webnamespace in the references section.
  5. Check whether the following namespaces are included in the SimpleServerControl.cs file.
    System
    System.Collections
    System.ComponentModel
    System.Data
    System.Web
    System.Web.SessionState
    System.Web.UI
    System.Web.UI.WebControls
    
  6. Inherit theSimpleServerControlsclass with the????????base class.
    public class SimpleServerControl : Control
  7. Override theRendermethod to write the output to the output stream.
    protected override void Render(HtmlTextWriter writer) 
    {
    	 writer.Write("Hello World from custom control");
    }
    
    ???:TheHtmlTextWriterclass has the functionality of writing HTML to a text stream. The?????? ??? ????HtmlTextWriterclass outputs the specified text to the HTTP response stream and is the same as theResponse.Write?????? ???
  8. Compile the class library project. It will generate the DLL output.
  9. Open an existing or create a new ASP.NET Web application project.
  10. Add a Web Forms page where the custom control can be used.
  11. Add a reference to the class library in the references section of the ASP.NET project.
  12. Register the custom control on the Web Forms page.
    <%@ Register TagPrefix="CC " Namespace=" CustomServerControlsLib " Assembly="CustomServerControlsLib " %>
  13. To instantiate or use the custom control on the Web Forms page, add the following line of code in the<form>tags.
    <form id="Form1" method="post" runat="server">
        <CC:SimpleServerControl id="ctlSimpleControl" runat="server">
        </CC:SimpleServerControl >
    </form>
    
    ???:?? ??? ???SimpleServerControlis the control class name inside the class library.
  14. Run the Web Forms page, and you will see the output from the custom control.
If you are not using Visual Studio, you need to perform the following steps:
  1. Open any text editor.
  2. Create a file named SimpleServerControl.cs, and write the code as given in steps 1 through 14.
  3. In the PATH variable, add the following path:
    c:\windows (winnt)\Microsoft.Net\Framework\v1.1.4322
  4. Start a command prompt, and go to the location where SimpleServerControl.cs is present.
  5. ????? ???? ?????:
    csc /t:library/????: CustomServerControlsLib. SimpleServerControl.dll /r:System.dll /r:System.Web.dll SimpleServerControl.cs
    C# ??????? (csc.exe) ?? ???? ??? ???? ??????? ?? ??? ????? MSDN ??? ???? ?? ????:
    (vs.71) http://msdn2.Microsoft.com/en-us/library/1700bbwd .aspx
  6. ??????? ?? ??? ??? ?? ????? ???????? ?? ????? ?? ??? ????? ?????:
    1. Wwwroot ??????? ?? ??????? ??? ?????????? ??????
    2. Microsoft ??????? ?????????? ???????? (IIS) ??????? ?? ??????? ????, ?? ??? ?????????? ??????? ??? ?????????? ?? ??? ??? ??????? ?????
    3. ??? ?????????? ?? ??????? ?? ??? ??????? ??????
    4. ????? ???????? DLL ??? ??????? ??? ????????? ?????
    5. ????? ??? ??????? ????? ???? ??? ?????????? ?? ???? ????? ??? ??? ?????
    6. ????? ????? ????? IIS ??????? ???
?? ???? ???? ?????? ????? ???????? ????? ??, ????? ????? ???? ??? ?????? ?? ???????-???? ??????? ????? ???????? ?? ?? ???? ?????

????? ???????? ?? ??? ?? ??????? ???? ?? ??? ???? ????

??? ????? ?????? ?? ????? ?? ??? ??????? ????? ?? ????? ???????? ?? ????? ???? ??? ???????? ?? ???? ??? ?? ?? ?? ???? ??? introduce ??????

????? ?????? ??????? ?? ??? ??? ???????? ??? ?? ?? ????? ????????? ???? ?? ?? ????????? ???? ?? ??? ???? ???????? ?? ??? ??? ????????? ?? ??? ???, ??? ?? ?? ??????? ??????:
  1. ???? ??? ?????? ??? SimpleServerControl.cs ?? ??????
  2. ???? ??? ??? ??????SimpleServerControl?????
    public class SimpleServerControl : Control
    {
       private int noOfTimes;
       public int NoOfTimes
       {
           get { return this.noOfTimes; }
           set { this.noOfTimes = value; }
       } 
       protected override void Render (HtmlTextWriter writer)
       {
         for (int i=0; i< NoOfTimes; i++)
         {
           write.Write("Hello World.."+"<BR>");
         } 
       }
    }
    
  3. ????? ???????? ?? ??????? ?????
  4. ??????? ?? ??? ??? ?? ????? ???????? ?? ?????, ???? ?? ??? ?? ??? ???????? declaration ??? ???????
    <CC:SimpleServerControl id="ctlSimpleControl" NoOfTimes="5" runat="server"></CC:SimpleServerControl>
  5. ????? ?? ?? ??? ?? ????? "Hello ?????" ?? ??? ??? ?? ??? ????? ???????? ?? ?? ??? ??? ????????? ???????? ?? ??? ??? ????????? ??????

????? ???????? ?? ???????-???? ????????? ?? ???? ???? ?? ??? ???? ????

??????-??? ????????? ????? ?????? ??
????? ?????? ??? ????? ????? ???????? ???????????? ??? ???? ??? ???????, ??? ?? Visual Studio ??? ?? ???????? ?? ????? ???? ????? ???, ?? ?? ?? ???? ???NoOfTimes?? ???????? ??? ?? ??????? ??? ????? ??? ????? ??????-??? ?? ????? ???????? ?? ?? ?? ???? ?? ??? ????

?? ???? ?? ?? ????? ?? ??? ?? Visual Studio, ???? ?? Visual Studio ????????? ??? ??? ??? ?????? ?? ????? ?? ???? ??? ?? ???? ?? ??? ???????? ??????? ?????? ???? ?? ???????? ??? ????????? ?? ????, ??? ????, ???, ?? ???? ????? ?? ??? ????????? ?? ???? ???? Visual Studio ????? ???????? ???? ?? ??? ???? ??, ?? ??? ???? ?? ????????? ?? ????, ????, ???, ?? ????? ???? ????????? ???? ?? ??? ???? ???? ?? ?? ????? ???????? ?? ??????? ??? ??????? ??????-??? ?? ??????

????????? ?? ???? ??? ???? ??????? ?? ????? ?? ??? ????? MSDN ??? ???? ?? ????:
(VS.71) http://msdn2.Microsoft.com/en-us/library/Aa288059 .aspx
????? ??????? ?? ????? ?? ?? ????????? ?? ????? ???? ?? ????? ?????????:
  1. ???? ??? ?????? ??? SimpleServerControl.cs ?? ??????
  2. ?????? ?? ???, ???? ???? ?? ??? ?????? ????????? introduce ????DefaultProperty,ToolboxData, ??TagPrefixAttrbute. ?? ?? ??? ????????? ?? ????? ????? ??????? ?????
            [
    	// Specify the default property for the control.		
    	DefaultProperty("DefaultProperty"),
    	
    	// Specify the tag that is written to the aspx page when the
            // control is dragged from the Toolbox to the Design view. 
    	// However this tag is optional since the designer automatically 
    	// generates the default tag if it is not specified.		
    	ToolboxData("<{0}:ControlWithAttributes runat=\"server\">" +
    		"</{0}:ControlWithAttributes>")
    	]
    	public class ControlWithAttributes : Control
    	{
    		private string _defaultProperty;
    		public string DefaultProperty
    		{
    			get { return "This is a default property value"; }
    			set { this._defaultProperty = value; }
    		}
    
    		protected override void Render(HtmlTextWriter writer)
    		{
    			writer.Write("Default Property --> <B>" + 
    			DefaultProperty + "</B>");
    		}
             }
    
  3. ???? ?? ???? ??? ??TagPrefixAttrbute. ?? ?? ??? ?? ??? ??? ?????? ?????? ???? ?? ?? ?? ?????? ???????? ????? ????? ?? designer ???????-???? ??????? ??? ??????, designer ????? "cc1" ???? ???? ?????? ???????? ??? ???TagPrefixAttrbute?? ???? ???? ???? ???????? ???? ?? ???? ???? ???? ?? ???TagPrefixAttrbute, AssemblyInfo.cs ?????, ??? ?? ????? ?????? ?? ????? ????, ?? ????????? ?? ???: ??????
    [assembly:TagPrefix("ServerControlsLib ", "MyControl")]
    ???:??? ?? ????? ????? ???? ?? ????? ?? ????? ?? ??? ????? ???, ?? ?? ???????? AssemblyInfo.cs ????? ????? ?? ??? ?????????? ?? ?????? ??? ????? ??????? ??? ????? ????, ?? ???????? ????? ?? ??? ????? ???? ?????:
    > csc /t:library/????: ServerControlsLib.dll /r:System.dll /r: System.Web.dll *.cs

???? ?????????? ???????? ?? ????? ???????? ?? ??? ??? ???? ????

?? ?? ?? ???? ?????????? ???????? ?? ????? ???????? ??? ?? ?????? ????? ?? ??? ???? ?? ?? ??? ????? ??, ?? ????? ????? ?? ??? ?? ???? ?? ??? ?????? ??? ?? ?????
?? ?????? ?? ??????? ?????? ?????? ?? ??????? ????
?????????????? ????????????? ????????
??????????-????????? ???????? ?? ??? ??????? ???? ???

????????? ?? ????? ??? ?? ??? ????? ??????? (.ascx) ??? ???? ????

??? ?? ?? ???? ????????? ??? ????? ???? ?? ??? ?? ?? ???????? ?? ???????? ??, ??? introduces ????????? ?? ?????? ????????
??????? ???? ??? ?? ?? ?? ?? ???? ????????? ?????? ????? ???? ?? ????

????????? ??? ?????????? ??? ?? ??????? ??????? ??? ??? ???? ????

????? ?? ?? ???? ????????? ?? ?????? ?? ??????? ???????? ?? ?????? ????
?????????????? ??? ??????? ????? ???; well-suited rapid ????????? ????? (RAD) ?? ??? ???? ?? ????? ?? ?? ???? ?????? involves ??? ?? ????? ???? ??????? ??????? ?????? ???? ??
????????? ???? ????? ?????? ?? ?? ??? ??????? ????? ??? ????? ??????? ?? ???????? ??, ?????? ?? ???, ?? ?? ????? ????? ??? ?? ??? ??????? ?? ???? ????????? ?? ??? ?????? ???????? ?? ??? suited ???? ????????? ???? ?? ??? ???????; ?? ???? ?? reused ???? ????????? ?? ??? ?????? ?? ???, ???? ?? ??? ????? ???????? ????????? ???? ?????? ?? ???????? ?? ???
?????????? ????????? designing ??????? ?? ??????-??? ?? ???? ?? mostly ????? ???? ???????? ????? ?? ???????? ??????????? ?? ???? ?? ???????? ?? ???? ???? ?? ???? ??? ?????? ????? ?????????, ?? ?? ??????? ??? ?? ??? ?? ????? ?? ?????????? ???????? ??? ?? ????? ??? ?? ???????? ??

????? ????

????, ???? ??? ?? ??? few ????? ???????? ?? ???? ??? ????? ?? ???? ?? ?? ????? ???????? ?? ?? ??? ?? ?????

????? ?? ???????

HTTP, stateless ?? ??? ?? ??? ????????? ?? ????? ??? ?? ????? ?? ???? ?????? ???????? ???????? ?????? ?? ????? ?? ?? disposed ??? ?????? ?? ???? ?? ??? ??? ???????? ASP ???????????? ??? ?????? ????, ?? ??? ?? ???? ?? ????????? ???????? ?? ????? ????? ????? ?? ???, ?? ???? ?????? ?? ????? ???? ?? ??? ??? ?? ?? ????, ?? ??? asp.NET ?????? ?? ??????? ??? ???? ???????? ?? ??? ?????? ???? ???? ?? ??? ????? ?????? ?? ??? ??? ???? ???? ??? ?????? ??????? ?? ????? ?????? ?? ???? ??? ???? ????? ?? ??? ????? MSDN ??? ???? ?? ????:
??? ??????? ?????? ?? ??????? ???? ?? ??? ?????
(vs.71) http://msdn2.Microsoft.com/en-us/library/75x4ha6s .aspx

ASP.NET ????? ??????
HTTP://MSDN.Microsoft.com/msdnmag/issues/03/02/cuttingedge/default.aspx

????? ????? ?????? ?? ????? ?? ??? ?? ?????? ??? ???????
(vs.71) http://msdn2.Microsoft.com/en-us/library/4yfdwycw .aspx
?????? ?? ????? ???????? ??? ????? ?????? ?? ????? ?? ??? ??
ViewStateExample.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;

namespace ServerControlLib
{
	/// <summary>
	/// When a page framework reloads this control after postback, it   
        /// will restore the values which are in view state.
	/// This control can easily perform state management without 
        /// implementing our own logic for maintaining the state.
	/// </summary>
	public class ViewStateExample : WebControl
	{
		// Text to be displayed in Text box control.
		private string _text;
		
		/*
		 * This property needs to be populated before every 
                 * postback in order to 
		 * retain its value.
		*/ 
		public string Text
		{
			get { return (_text == null) ? "_text property is empty"  : _text; }
			set { _text = value; }
		}

		/*
		 * This property needs to be filled once and should be 
                 * available on the successive postbacks.
		*/ 
		public string TextInViewState
		{
			get
			{
				object o = ViewState["TextInViewState"];
				return (o == null) ? "View state is empty" : (string)o;
			}
			set { ViewState["TextInViewState"] = value; } 
		}

		/*
		 * Over-ridden method on WebControl base class which                   
                 * displays both of the property values 
		 * i.e. one stored in view state and other which is not 
                 * saved in view state.
		*/
		protected override void RenderContents(HtmlTextWriter writer)
		{
			writer.Write("Text Without View State = ");
			writer.Write(Text);
			writer.Write("<hr><br>");
			writer.Write("Text In View State = ");
			writer.Write(TextInViewState);
		}
	}
}
???? ??????? ?? ??? ??? ?? ????? ???????? ?? ????? ???? ??? ??????
ViewStateExampleDemo.aspx
<%@ Page Language="C#" %>
<%@ Register TagPrefix="CC" Namespace="ServerControlLib" Assembly = "ServerControlLib" %>

<html>
  <head>
    <script runat="server">
      void button1_Click(object sender, EventArgs e)
      {
          Control1.Text = textbox1.Text;
          Control1.TextInViewState = textbox2.Text;
      }
    </script>
  </head>
  <body>
    <form runat="server" ID="Form1">
      <br>
      Property Value Without View State: <asp:TextBox id="textbox1" 
        runat="server" />
      <br>
      Property Value with View State: <asp:TextBox id="textbox2" 
        runat="server" />

      <asp:Button text="Cause Postback" onClick="button1_Click" 
        id="button1" Runat="server" />

      Output from the ViewStateExample Control :
      <CC:ViewStateExample id="Control1" runat="server"/>
    </form>
  </body>
</html>

????????

?? ??? ???, ??? ???? ??????? ????? ??? ??????? ?? ?? ?? ??? ????? ???????? derive ?? ??????? ???? ????????????????? ??WebControl?????
System.Web.UI.Control ???? ?? ???????? ???????
???????? ??????? ?? ???? ??? ??????? ?? ???System.Web.UI.Control???? ?? ???, ????? MSDN ??? ???? ?? ????:
Control.Render????
(vs.71) http://msdn2.Microsoft.com/en-us/library/SYSTEM.Web.UI.control.render .aspx

Control.RenderControl????
(vs.71) http://msdn2.Microsoft.com/en-us/library/SYSTEM.Web.UI.control.rendercontrol .aspx

Control.RenderChildren????
(vs.71) http://msdn2.Microsoft.com/en-us/library/SYSTEM.Web.UI.control.renderchildren .aspx
???? ???????? ????? ?? ???? ??
???????? ????? ?? ???????? ???? ?? ?? ?? ??? ?? ??? ??? ?????? ???????? ?? ?????? ?? ???????????? ???? ??? ???????? ????, ??? ??? ???????? ?? ????? ???? ?? ???HtmlTextWriter???? ?? ??????? ???????? ?? ???? ?? ??? HTML ??? ????? ??? ??? ?? ???????? ?? ??? ???? ??? ??RenderControl?????? ??? ???? ???,RenderControl???? invokes??????????? ??? ???,????????? ???RenderChildren???????? ?????? ???????? ?? ?????? ?? ????? ?????? ?? ??? ?? ?? recursive ??? ?? ????? ??? This process is best explained by the following example code.
public void RenderControl(HtmlTextWriter writer) 
{
    // Render method on that control will only be called if its visible property is true.
    if (Visible)
    {
        Render(writer);
    }
}

protected virtual void Render(HtmlTextWriter writer) 
{
    RenderChildren(writer);
}
protected virtual void RenderChildren(HtmlTextWriter writer) 
{
    foreach (Control c in Controls) 
    {
        c.RenderControl(writer);
    }
} 
Rendering methods of the System.Web.UI.WebControl class
For information about the rendering methods of theSystem.Web.UI.WebControlclass, visit the following MSDN Web sites:
WebControl.RenderBeginTagmethod
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.renderbegintag(vs.71).aspx

WebControl.RenderContentsmethod
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.rendercontents(vs.71).aspx

WebControl.RenderEndTagmethod
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.renderendtag(vs.71).aspx
How the rendering of the WebControl class takes place
The following code example shows theRendermethod for the custom control.
protected override void Render(HtmlTextWriter writer)
{
    RenderBeginTag(writer);
    RenderContents(writer);
    RenderEndTag(writer);
}
You don't need to override theRendermethod for theWebControl????? ??? ?? ??? ??????? ?? ????? ???? ????? ???WebControl???? ?? ???, ???? ??????? ???? ?? ???RenderContents?????? ??? ???????, ??? ?? ??? ?? ????? ??????? ???? ?? ???????????? ?? ???, ???? ?????? ???????RenderBeginTag???? ??? ?? ???RenderEndTag?????? ??? ??????? ???? ?? ????? ??? ?????? ??? ?????? ??? ???

Conclusion

??? ?? ?? ?????????? ???????? ?? asp.NET 1.0 ?? asp.NET 1.1 ??? ????? ???????? ?? ??? ?? ???? ???? ??? ?? ?? ?? ????? ??? ???? ?? ?????? ?? ??????? approaches ?????? ?????? ???? ?? ??? ?? ?? ???? ??? ?? ??? ??? ???? ?? ????? ????

???? ??? ?? ??? ???? ???????? ?? ????? ????????, ???? ?? ?????? ???????, ???????? ???????, ????????? ????????, ?? ????? ???????? ?? ??? ???????-???? ?????? ?? ??? ????? ?????? ?? ???? ??? ???? near ?????? ??? ????? ?? ??? ??????? ???

???????? ?? ???? ??? ???? ??????? ?? ??? ????? MSDN ??? ???? ?? ????:
?????? asp.NET ????? ???????? ????? ?????
(vs.71) http://msdn2.Microsoft.com/en-us/library/aa310918 .aspx

?????????? ???????? ?? ?? ??????? examination
HTTP://msdn2.Microsoft.com/en-us/library/ms972975.aspx

??? templated ????? asp.NET ????? ????????
HTTP://msdn2.Microsoft.com/en-us/library/Aa478964.aspx

ASP.NET ????? ???????? ??? ???????
(vs.71) http://msdn2.Microsoft.com/en-us/library/aa720049 .aspx

?????????? ???????? vs. ??????? ????????
(vs.71) http://msdn2.Microsoft.com/en-us/library/aa719735 .aspx

ASP.NET ????? ???????? ??
(vs.71) http://msdn2.Microsoft.com/en-us/library/aa719973 .aspx

????? ???????? ??: ????????? ?????
(vs.71) http://msdn2.Microsoft.com/en-us/library/aa720226 .aspx

ASP.NET ?? ???????? ???? ?? ??? ???????-???? ?????? ???? ??? ??
HTTP://msdn2.Microsoft.com/en-us/library/Aa478960.aspx
?????, ?????? ?????? ?? ???? ????? ???? ?? ??? ????? ?????? ??????? ?????? ??? ??????? ?? ??? ??? ?? ???????? ????? ??? ????? ?? ??? ?????????????

???

???? ID: 893667 - ????? ???????: 30 ??????? 2010 - ??????: 4.0
???? ???? ???? ??:
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
??????: 
kbhowto kbasp kbmt KB893667 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:893667

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com