如何在另一个用户控件中使用一个 asp.net 用户控件? [英] How do I use an asp.net user control in another user control?

查看:28
本文介绍了如何在另一个用户控件中使用一个 asp.net 用户控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件 (gallery.ascx),我想在画廊控件中使用 photo.ascx 控件.我在 gallery.ascx 的顶部添加了这个寄存器,但它仍然找不到照片:

I have a user control (gallery.ascx) and I want to use the photo.ascx control in the gallery control. I've added this register at the top of gallery.ascx, but it still can't find photo:

<%@ Register TagPrefix="ssctrl" TagName="photo" Src="controls/photo.ascx" %>

有什么想法吗?

推荐答案

如果有人想知道,Register 是否正确,只是我的照片用户控制标签没有正确形成.我确实有它:

In case anyone is wondering, the Register is correct, my photo user control tag was just not formed properly. I did have it as:

<ssctrl:photo ID="Photo" Key="<%# Eval("PageTemplatePK") %>" runat="server" />

并且 Key 属性需要使用单引号而不是双引号,因为它使用的是 Eval 表达式:

and the Key property needed to use single quotes instead of double quotes because it was using an Eval expression:

<ssctrl:photo ID="Photo" Key='<%# Eval("PageTemplatePK") %>' runat="server" />

在那之后,它起作用了.

After that, it worked.

这篇关于如何在另一个用户控件中使用一个 asp.net 用户控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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