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"
Advertisements
Tagged , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: