今天学着用FreeTextBox,FreeTextBox将它的资源和程序都集成到DLL中去了,而且可以制作成控件让我们通过拖拽的方式使用。那面就说说如何将FreeTextBox做成控件了。
右键“工具箱(就是放控件的地方)”,然后选择“选择项”,这个过程可能有点慢,等将近1分钟的时间,然后再.net framework组件选项卡下点击“浏览”,然后找到我们"FreeTextBox.dll"的存放路径。添加进去就OK了。这时候我们回到“工具箱”就能找到我们添加的控件"FreeTextBox",工具箱中的控件时有分类的, 如果我们刚才在“登录”分类中添加的控件,那么现在也就去“登录”分类中查找。
将"FreeTextBox"空间托到aspx页面中,我们可以知道它的代码是
<FTB:FreeTextBox ID="FreeTextBox1" runat="server"></FTB:FreeTextBox>
在写aspx的时候,不注意把AutoEventWireup="false"去掉,你可能会死得很难看,
Page_load部分会在一次页面加载的时候执行两次哦!千万注意不要去掉aspx中的
AutoEventWireup="false"设置。
<%@ Page language="c#" Codebehind="ShowSimpleFactory.aspx.cs" AutoEventWireup="false" Inherits="test.DesignPatternTest.ShowSimpleFactory" %>
当你将这个属性设置为true时,Asp.Net将页面的生命周期事件与一些特殊的方法进行关联,比如将你的Page_Load方法直接关联到页面生命周期的OnPageLoad事件。如果你将这个属性设置为false,那么这种自动的关联将不存在,你需要自己设置OnPageLoad事件的处理程序。
一般你将这个属性设置为false后,你可以获取少许的性能提升。
Microsoft 建议始终将 AutoEventWireup 设置为 FALSE。
MVCHandler : IHttpHandler
void IHttpHandler.ProcessRequest(HttpContext httpContext)
{
this.ProcessRequest(httpContext);
}
protected virtual void ProcessRequest(HttpContext httpContext)
{
HttpContextBase base2 = new HttpContextWrapper(httpContext);
this.ProcessRequest(base2);
}
protected internal virtual void ProcessRequest(HttpContextBase httpContext)
{
IController controller;
IControllerFactory factory;
this.ProcessRequestInit(httpContext, out controller, out factory);
try
{
controller.Execute(this.RequestContext);
}
finally
{
factory.ReleaseController(controller);
}
}
Controller : ControllerBase : IController
void IController.Execute(RequestContext requestContext) //------>Controller
{
this.Execute(requestContext);
}
protected virtual void Execute(RequestContext requestContext) //------>ControllerBase
{
if (requestContext == null)
{
throw new ArgumentNullException("requestContext");
}
if (requestContext.HttpContext == null)
{
throw new ArgumentException(MvcResources.ControllerBase_CannotExecuteWithNullHttpContext, "requestContext");
}
this.VerifyExecuteCalledOnce();
this.Initialize(requestContext);
using (ScopeStorage.CreateTransientScope())
{
this.ExecuteCore();
}
}
protected override void ExecuteCore() //------>Controller
{
this.PossiblyLoadTempData();
try
{
string requiredString = this.RouteData.GetRequiredString("action");
if (!this.ActionInvoker.InvokeAction(base.ControllerContext, requiredString)) //public IActionInvoker ActionInvoker { get; set; }
{
this.HandleUnknownAction(requiredString);
}
}
finally
{
this.PossiblySaveTempData();
}
}
ControllerActionInvoker : IActionInvoker
public virtual bool InvokeAction(ControllerContext controllerContext, string actionName)
{
if (controllerContext == null)
{
throw new ArgumentNullException("controllerContext");
}
if (string.IsNullOrEmpty(actionName))
{
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "actionName");
}
ControllerDescriptor controllerDescriptor = this.GetControllerDescriptor(controllerContext);
ActionDescriptor actionDescriptor = this.FindAction(controllerContext, controllerDescriptor, actionName);
if (actionDescriptor == null)
{
return false;
}
FilterInfo filters = this.GetFilters(controllerContext, actionDescriptor);
try
{
AuthorizationContext context = this.InvokeAuthorizationFilters(controllerContext, filters.AuthorizationFilters, actionDescriptor);
if (context.Result != null)
{
this.InvokeActionResult(controllerContext, context.Result);
}
else
{
if (controllerContext.Controller.ValidateRequest)
{
ValidateRequest(controllerContext);
}
IDictionary<string, object> parameterValues = this.GetParameterValues(controllerContext, actionDescriptor);
ActionExecutedContext context2 = this.InvokeActionMethodWithFilters(controllerContext, filters.ActionFilters, actionDescriptor, parameterValues);
this.InvokeActionResultWithFilters(controllerContext, filters.ResultFilters, context2.Result);
}
}
catch (ThreadAbortException)
{
throw;
}
catch (Exception exception)
{
ExceptionContext context3 = this.InvokeExceptionFilters(controllerContext, filters.ExceptionFilters, exception);
if (!context3.ExceptionHandled)
{
throw;
}
this.InvokeActionResult(controllerContext, context3.Result);
}
return true;
}
protected virtual void InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
{
actionResult.ExecuteResult(controllerContext);
}
ActionResult
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if (string.IsNullOrEmpty(this.ViewName))
{
this.ViewName = context.RouteData.GetRequiredString("action");
}
ViewEngineResult result = null;
if (this.View == null)
{
result = this.FindView(context); //ViewEngineResult
this.View = result.View; //IView接口
}
TextWriter output = context.HttpContext.Response.Output;
ViewContext viewContext = new ViewContext(context, this.View, this.ViewData, this.TempData, output);
this.View.Render(viewContext, output);
if (result != null)
{
result.ViewEngine.ReleaseView(context, this.View);
}
}