How do I add a value to a TextBox that's inside an ASP:LoginView
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 addString.Empty
totxtEventName.Text
that's inside theLoginView
which has an ID of "loginview2"?And how do I add a value to a
TextBox
andDropDownList
inside anLoginView
called "loginview2" where I have aTextBox
with the ID textEventName.Text and theDropDownList
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.
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.