How do I add a value to a TextBox that's inside an ASP:LoginView

I have some DropDownLists and some TextBoxes on a page. Normally I use this to clear and add value to the items:

Clear control:

txtEventNote.Text = String.Empty
ddlHours.SelectedIndex = 0

Add value:

ddlHours.SelectedValue = dtEvents.Rows(0)("EventDate")
txtEventTitle.Text = dtEvents.Rows(0)("EventHome").ToString()

But if I do this for items thats inside an ASP:LoginView I get an error because the ID's cant be found.

So my question is:

  • How do I clear the ddlSize DropDownList ID and how do i add String.Empty to txtEventName.Text that's inside the LoginView which has an ID of "loginview2"?

  • And how do I add a value to a TextBox and DropDownList inside an LoginView called "loginview2" where I have a TextBox with the ID textEventName.Text and the DropDownList have ID ddlSize.

If I delete the LoginView it's easy for me to do, but when I add the LoginView the ID's can't be found.

Answers


The LoginView control is a container control. It can hold other ASP.NET WebForm controls. To get a reference to the controls contained within the LoginView control use the FindContol method of the LoginView control.

TextBox tb = lcLoginView.FindControl("txtEventNote") as TextBox
if (tb != null)
{
     tb.Text = "My New Value For This TextBox control";
}

Do the same for your DropDownList.

I found In Search Of ASP.Net Controls to be helpful for more about finding ASP.NET controls in other ASP.NET controls.


Need Your Help

Order object_list with django-profiles

django django-profiles

Using the django-profiles app, I want to display the users' profiles in an ordered list.

Testing number of outliers of opencv warpAffine

c++ opencv affinetransform outliers ransac

I'm using opencv to estimate the affine transform between two images (let's call it A and B, and I want to estimate from A to B), and I need to implement RANSAC to get the best estimation possible....

Rspec - post - MassAssignmentSecurity::Error

ruby rspec ruby-on-rails-3.2 mass-assignment

I have few models: User and Article. User has_many articles and Article belongs to user.