在 LoginView 中引用 ASP 控件

发布于 2024-08-28 18:30:39 字数 443 浏览 4 评论 0原文

恐怕另一个完全的新手问题:我有一个 LoginView ,里面有一些 HyperLinks ,但是当我尝试在它后面的代码中引用超链接时,它告诉我:它不存在于“当前上下文”中。

例如。 hypLink1.NavigateUrl = "some/link/on/my/site.aspx"

我发现这只是因为它在 LoginView 中找不到它...那么我该怎么做才能让它查看 LoginView 内部呢?

我认为这可能是直观的,例如:

LoginView1.hypLink1.NavigateUrl = "some/link/on/my/site.aspx"

但无济于事。

感谢您对这个(最有可能)非常明显的问题的任何帮助!

Another total newb question, I'm afraid: I have a LoginView with some HyperLinks inside it, but when I try to reference the HyperLink in the code behind it tells me that it doesn't exist in the "current context".

eg. hypLink1.NavigateUrl = "some/link/on/my/site.aspx"

I've figured out that it's only because it's in the LoginView that it can't find it... so what can I do to tell it to look inside the LoginView?

I thought it might be something intuitive like:

LoginView1.hypLink1.NavigateUrl = "some/link/on/my/site.aspx"

But to no avail.

Thanks for any help with this (most likely) really obvious problem!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我早已燃尽 2024-09-04 18:30:39

我猜您正在尝试从登录视图控件外部引用超链接?

此时,您可以在 LoginView 上尝试 FindControls 操作:

HyperLink hypLink1 = (HyperLink)LoginView1.FindControls("hypLink1");

UPDATE

好的,所以我对您的问题感到困惑。 LoginView 控件仅允许 FindControls,因此您必须使用上面的代码片段才能引用其内部控件。

由于LoginView控件使用模板,因此在不同的情况下会存在不同的控件。因此,代码无法确保模板内的任何给定控件在编译时都处于活动状态。

因此,每次您想要获取子控件时,您都必须 FindControls :'(

I'm guessing that you're trying to reference the hyperlink from outside the loginview control?

At that point, you could try a FindControls operation on the LoginView:

HyperLink hypLink1 = (HyperLink)LoginView1.FindControls("hypLink1");

UPDATE

Ok, so I was confused as to what you were asking. The LoginView control only allows FindControls, and so you have to use the code snippet up above in order to reference controls internal to it.

Since the LoginView control uses templates, different controls will exist under different circumstances. As such, the code cannot ensure any given control inside the template will be alive at compile time.

So you'll have to FindControls every time you want to get a child control :'(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文