动态添加控件及其事件
我在 asp.net 中遇到问题
我正在使用 (asp.net/vb) 在 Visual Studio 2008 中开发一个网站
我必须允许注册用户构建页面并添加已由同一用户定义的控件。
我的问题是如何动态构建此页面?
换句话说,我想像任何CMS(例如Joomla)一样。 CMS 允许我们制作新页面并添加控件,然后保存它们...
我想了很多,我通过制作一个代码生成器(从 A->Z)来生成页面及其隐藏代码(apsx)找到了解决方案文件和aspx.vb文件)
有什么工具或解决方案可以比我的解决方案更好地帮助我吗?
任何帮助表示赞赏。
I have a problem in asp.net
I'm developing a website in visual studio 2008 using (asp.net/vb)
I have to allow registered users to build pages and add controls that are already defined by the same user.
My problem is how to build this page dynamically?
In other words, I'd like to make like any CMS (e.g. Joomla). CMSs allow us to make new pages and add our controls then save them...
I think alot and I find a solution by making a code-generator (from A->Z) that generates the page and its code-behind (apsx file & aspx.vb file)
Is there any tool or solution can help me better than my solution??
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看 aspx 页面的设计器 cs 文件,您会注意到设计器在运行时向页面的控件添加对象。如果需要,您可以在运行时让编译器服务为页面生成一个类,或者您可以创建一个函数,通过类型名称创建控件的实例,然后将该对象添加到页面中。
这将返回创建的控件,然后您可以按照设计器的相同方式连接该控件。
编辑:或者您可以查找编译器服务。我曾经编写过一个程序,它采用基于 xml 的配置文件,并使用字符串生成器将其转换为可编译的 .cs 文件。然后我使用编译器服务将该文本编译到我执行的类中。它的开始是这样的:
最终是这样的
根据这些信息
基本上,字符串构建器对每个属性采用:“public {0} {1}{get;set;}”,然后根据以下值构建最终字符串xml。然后编译器服务将其转换为一个类。课程制作完成后,可以将其存储起来以供将来使用。我所做的另一个尝试是在网站项目中运行磁盘上的代码文件,然后调用该站点重新启动(这有效地重新编译了 IIS 在目录中找到的所有内容,包括新的代码文件)。
可能性:)
If you look at the designer cs file for an aspx page you will notice that the designer is adding objects to the controls for the page at runtime. If you want, you could the compiler services at run time to generate a class for the page, or you could create a function that creates an instance of the control by it's type name and then add that object to the page.
Which will should return the created control, that you can then hookup in the same way that the designer does it.
EDIT: Or you could look-up compiler services. I once made a program that took it's xml based config file, and turned it into a compilable .cs file using string builder. Then I used compiler services to compile that text into a class which I executed. It started life like this:
and ended up like this
based on this information
Basically the string builder took: "public {0} {1}{get;set;}" for each property then built the final string based on the values of the xml. Compiler services then turned it into a class. Once the class was made it could be stored for future use. Another attempt I did was to run the code file out disk in a web site project, then called the site to restart (which effectively recompiled all the that IIS finds in the directory, including your new code files).
The possibilities :)