Tag Archives: VB.NET

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 , ,

Check if an ASP.NET CheckBoxList items are Checked or Unchecked

The VB.NET code to check if an ASP.NET CheckBoxList items are Checked or Unchecked:

Dim i as integer

for i = 0 to checklistbox1.items.count -1
if checklistbox1.item(i).selected = false then
'do something here
else
'do something if they are checked.
end if
next

Tagged , ,