Asp.net声明添加控件。他们在哪里实例化? [英] Asp.net declaratively adding controls. Where are they instantiated?

查看:431
本文介绍了Asp.net声明添加控件。他们在哪里实例化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直让回asp.net web表单,我有一个关于控制问题。
当我声明添加一个控制按钮,例如到一个aspx页面(通过拖动和删除从工具箱中控制IE),我所期待的出现是被宣布并在designer.cs文件实例化一个按钮对象
相反,所有我能找到的是

Ive been getting back into asp.net web forms and I had a question about the controls. When I add a control declaratively (ie by dragging and drop a control from the toolbox), for instance a button onto an aspx page, what I expected to occur was for a button object to be declared and instantiated in the designer.cs file Instead all I can find is

protected global::System.Web.UI.WebControls.Button ButtonTest;

但无处我能找到创建一个新的按钮对象,并将其分配给ButtonTest的code。有谁知道在哪里/发生这种情况时?

but nowhere can I find the code that created a new button object and assigns it to ButtonTest. Does anybody know where/when this occurs?

推荐答案

它曾经沿着你所描述的线工作,早在NET 1.1天。引进部分类允许的方式加以简化,所以你通常没有直接与产生code交互。

It used to work along the lines you describe, back in .NET 1.1 days. The introduction of partial classes allowed that approach to be simplified, so you normally don't have to directly interact with the generated code.

如果你想看看到底是什么框架做:标记被编译成一个部分类,其中包含了网页上的对象的声明,通过调用构造函数一起等

If you'd like to see exactly what the framework is doing: the markup gets compiled into a partial class, which contains the declarations for the objects on the page, along with calls to constructors, etc.

您无法轻松地查看从Visual Studio自动生成的code。看到它,启用调试为您的项目,并期待在:

You can't easily view the auto-generated code from Visual Studio. To see it, enable debugging for your project and look in:

C:\\ WINDOWS \\ Microsoft.NET \\框架\\ v4.0.30319 \\临时ASP.NET文件\\

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\

源$ C ​​$ C的编译的文件应该在那里的子目录中的一个。

The source code for the compiled file should be in one of the subdirectories there.

更容易,如果你创建在你的页面的小编译错误,然后尝试在浏览器中查看它,你应该看到的错误页面,让您查看底部的链接编译源。

Even easier, if you create a small compilation error in your page, then try to view it in a browser, you should see a link at the bottom of the error page that lets you view the "compilation source."

这篇关于Asp.net声明添加控件。他们在哪里实例化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆