Enter the value of the <asp: FormView> field from the code behind.
I am using an asp: FormView element with elements like:
<asp:TextBox id="FirstName"
runat="server" MaxLength="20"
Columns="15" Text='<%# Bind("FirstName") %>' />
I cannot access the value of this field by its id → "FirstName" in the file behind the code.
Any ideas on how I can access this value in code behind the file?
+3
source to share
1 answer
You will need to use FindControl on the FormView to access the textbox:
var firstNameTextbox = FormViewId.FindControl("FirstName") as TextBox;
string myValue = firstNameTextbox.Text;
You should also notice that this will only work after you have data bound to the FormView. Typically you will handle the FormView's DataBound event and execute it there.
+6
source to share