Monthly Archives: May 2015

How to access ASP.NET Controls from code-behind inside a LoginView control

I almost created a completely new project as i thought it was one of those unexplained Visual Studio phenomenons. As a last measure I consulted Dr.Google and voila!

The following example holds true for any control, just make sure to add the corresponding attributes and values for casting.

(All codes in VB,NET)

To access a TextBox Control

Dim tbox As TextBox = DirectCast(LoginView1.FindControl("TextBox3"), TextBox)
tbox.Text = "WOW"

To access a Image Control

Dim picture As Image = DirectCast(LoginView1.FindControl("img1"), Image)
picture.ImageUrl = "pics/thumbs/what.png"

To access a Label Control

Dim labelname As Label = DirectCast(LoginView1.FindControl("label1"), Label)
labelname.Text ="last"
Tagged , ,