Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top