How do I refer to a FormView object, say a TextBox control, in my ASP .NET VB code? The obejects have names, but I can't seem to refer to them in VB code. Any ideas?
Click each button to view the code examples on this page, should help: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/formview.aspx
Thanks for the reply! I did what you suggested. However, all the examples refer to the ASP code. What I want to do is refer to ViewForm objects in my Visual Basic code. For example: a View Form obect, say NameTextBox, doesn't seem to be recognized in VB code, as in "NameTextBox.Text = 'whatever'" Any ideas?
The FormView control is a templated naming container control and provides it's own naming scope for child controls; this means you need to use FindControl to find relevant controls in the "current" template. I'm a C# guy myself so here's a little snip that I've copied and pasted from elsewhere - I hope the syntax is accurate. Code: If FormView1.CurrentMode = FormViewMode.Edit Then ' Find the TextBox with the id TextBox1 in the FormView's EditItemTemplate Dim tb As TextBox = CType(FormView1.FindControl("TextBox1"), TextBox) Response.Write(tb.Text) End If If you have other templates defined in your FormView, you can easily extend this code to check the CurrentMode property for other FormViewModes as required.
...Good job Joe, thx ;-) As for the ASP.NET reference, use the tools on the top of that site. The code examples are in ASP.NET for VB or C#. It's not the best resource on-line but it is good. You may also want to use the ASP.NET forums, you'll find some great Developers helping there. All the best, Mark