开发者

Referencing an ASP control within a LoginView

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 conte开发者_运维问答xt".

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!


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 :'(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜