如何加载另一个项目的用户控逆变? [英] How to load the user contol from another project?

查看:78
本文介绍了如何加载另一个项目的用户控逆变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/709617/using-user-controls-from-other-projects-in-asp\">Using从ASP 其他项目的用户控件

Possible Duplicate:
Using User Controls from Other Projects in ASP

我有以下情况:一个解决方案有两个项目,A和B其中之一,A,有一个用户控件

I have the following case: A solution has two projects, A and B. One of them, A, has a UserControl.

现在我建立A和B.添加到引用怎么可能装载在B中的用户控制和访问该用户控制控制?

Now I build A and add a reference to A in B. How is it possible to load the user control in B and access the controls in that user control?

我想避免重建项目 B 我每次改变用户控件的一次?

I want to avoid to rebuild Project B every time i change one of the user controls ?

推荐答案

我用它来进行这样的,与IIS工作,ASP.NET 4.0:

I use to proceed like this, working with IIS, ASP.NET 4.0 :


  1. 将控制myControl.ascx我想在名为Application A的子文件夹共享的 SharedControls

  2. 在IIS中,添加一个虚拟目录(没有应用程序,但执行脚本的权利),以B,ASharedControls,指着A的的 SharedControls 的(引用这个子目录,你会避免b包括A的网页的.config在它的层次结构,这将使得B崩溃)

  3. 在B,添加项目引用到A

  4. 在B,你现在可以声明和标记与使用您的控件
    &LT;%@注册标签preFIX =UC1变量名=显示myControlSRC =〜/ ASharedControls / myControl.ascx%&GT; (VS会警告因为没有找到路径,但它应该在IIS工作)

  5. myControl然后应在codebehind也可用于B的页面和控件

  1. Place the control myControl.ascx I want A to share in a subfolder of Application A named SharedControls
  2. in IIS, add a virtual directory (no app, but with execute script rights) to B, 'ASharedControls', pointing on A's SharedControls (referencing this subdirectory, you will avoid B including A's web.config in it's hierachy, which would make B crash)
  3. In B, add a project reference to A
  4. In B, you can now declare and use your control in markup with <%@ Register TagPrefix="uc1" TagName="myControl" Src="~/ASharedControls/myControl.ascx" %> (VS will warn as path not found, but it should work in IIS)
  5. myControl should then be also available in codebehind for B's pages and controls

根据您的页面和控件是$ C $的CFile / codebehind,你可能在web.config中编译元素设置一批=假,以避免多编译冲突:

Depending on your pages and controls being codefile/codebehind, you might have to set batch="false" in web.config compilation element, to avoid multi-compilation conflicts :

<compilation defaultLanguage="c#" debug="true" batch="false" targetFramework="4.0">

希望这将有助于

这篇关于如何加载另一个项目的用户控逆变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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