为什么我的用户控件不渲染? [英] Why don't my user controls render?

查看:74
本文介绍了为什么我的用户控件不渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在vb.net中创建了一组用户控件,并且在其原始项目中它们可以正常工作.

I've created a set of user controls in vb.net and in their original project they work fine.

此后,我创建了一个用户控制库dll,希望在新项目中使用它.

I've since created a user control library dll and I wish to use it in a new project.

我将对dll的引用添加为罚款,在asp.net页面中指定标签库,并在页面上定义控件.

I add the reference to the dll fine, specify the tag library in an asp.net page fine and define controls on the page fine.

除了我没有渲染输出,一切似乎都可以正常工作.

Everything seems to work except I get no rendered output.

各种控件和page_load方法都被调用.

Various properies of the controls and the page_load methods are all called.

Asp.net跟踪显示页面层次结构中的控件等

Asp.net trace shows the controls in the page hierarchy etc

在控件应该放置的地方没有输出-有什么建议吗?

Just no output where the controls should be - any suggestions?

我只是比较了工作输出与不工作的痕迹.

I just compared a trace of the working output compared to the non working.

工作输出包含用户控件(及其中的所有元素)无效的输出仅列出用户控件-没有内容

The working output contains the user controls (and all elements in them) The non working output only lists the user controls - no content

因此,似乎控件的内容有所丢失-好像标记未与背后的代码一起编译,仅背后的代码似乎在工作.

It therefore seems that the content of the controls is missing somehow - as if the markup is not being compiled with the codebehind, only the codebehind seems to be working.

控件是继承自UserControl而不是控件.

The controls are inheriting from UserControl not control.

推荐答案

您对Update 1的总结是正确的,您的标记未包括在内!

You are correct in your summarization in Update 1- your markup has not been included!

如果您试图在.dll中分发.ascx控件,则需要提供一些肘部润滑脂,但要感谢的是不要太多.

You need to provide a bit of elbow grease if your trying to distribute .ascx controls in a .dll but not too much thankfully.

您需要做的两件事:

  1. 嵌入.ascx控件. .ascx控件需要标记为.dll中的嵌入式资源(与内容"相对)
  2. 创建VirtualPathProvider .这样一来,您就可以直接从嵌入的dll中加载ascx文件.
  1. Embedded your .ascx controls. The .ascx controls need to be marked as an embedded resource in your .dll (as oppossed to 'content')
  2. Create a VirtualPathProvider. This will allow you to load the ascx files directly from the dll they are embedded in.

不幸的是,步骤2的解释有些冗长,但是这篇出色的文章帮助我完全按照自己的意愿去做.

Unfortunately explaining step 2 is slightly lengthy, however this excellent article helped me out in doing exactly what you want to do.

分发这样的.ascx控件的好处在于,您不必费心编写自定义控件(渲染任何比非常简单的html都更有意义的噩梦).

The beauty of distributing .ascx controls like this is that you dont have to tear your hair out writing custom controls (rendering anything over than very simple html is a nightmare to make sense of).

这篇关于为什么我的用户控件不渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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