Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access<asp:FormView> field value from code behind.

I have am using an asp:FormView control with elements such as:

<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 code behind file.

Any ideas on how I can access that value in the code behind file?

like image 784
Baxter Avatar asked Jun 19 '26 01:06

Baxter


1 Answers

You'll have to use FindControl on the FormView to get access to the textbox:

var firstNameTextbox = FormViewId.FindControl("FirstName") as TextBox;
string myValue = firstNameTextbox.Text;

You should also note that this will only work after you have bound the data to the FormView. Typically you would handle the DataBound event of the FormView and do it there.

like image 55
patmortech Avatar answered Jun 21 '26 00:06

patmortech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!