在 LoginView 中引用 ASP 控件
恐怕另一个完全的新手问题:我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜您正在尝试从登录视图控件外部引用超链接?
此时,您可以在 LoginView 上尝试 FindControls 操作:
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:
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 :'(