 |
BOOK: Beginning ASP.NET 1.0  | This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 1.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

August 30th, 2004, 06:32 AM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Form Text Boxes
Hello,
I am wondering how to display information from a database in a textbox on a web form using VB.NET. I know that the following code doesn't work because the collection is read-only:
objSomething = Request.form("txtFName")
Can someone please tell me or direct me in the right direction on how to get this to work. My reasoning for doing this is to display User details so they may be updated via a form.
Thanks in Advance,
Mark.
|
|

August 30th, 2004, 07:40 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
Get the data into a DataSet or DataTable, then do:
'If using dataset, get the specific Data table
Dim objTable As DataTable = objDataSet.Tables(0)
If (objTable.Rows.Count > 0) Then
Dim objRow As DataRow = objTable.Rows(0)
TextBox1.Text = objRow("FieldName").ToString()
End If
Brian
|
|

August 30th, 2004, 09:06 AM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the reply Bmains,
But txtSomething.text is a server control in ASP.NET however I must use HTML textboxes...(i.e. <input text..so on)
Any advice?
Thanks,
Mark
|
|

August 30th, 2004, 02:38 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
You have to make the control server-based anyways, by adding a runat="server", which in both server-based and html-based forms, would look like:
<asp:TextBox id="TextBox1" runat="server"/>
<input type="text" id="TextBox1" runat="server"/>
The textbox absolutely has to have the runat="server" attribute.
Brian
|
|

August 31st, 2004, 07:07 AM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hey,
I put in the runat tag, but still get an error. I know that the error is caused by the Request.Form collection is read-only, therefore I can't set values from the DB to the textboxes on the form.
How can I can the get the values from the DB to display in the textboxes on the form so a user may be able to editing those values.
Thanks,
Mark
|
|

August 31st, 2004, 11:49 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
Use TextBox1.Text, as stated previously. Don't use Request.Form. The Textbox, with runat="server", can access the textboxes directly, or any other server control for that matter.
Brian
|
|

August 31st, 2004, 12:54 PM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Brian,
But I now encounter the following error:
------
The base class includes the field 'txtname', but its type (System.Web.UI.WebControls.TextBox) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlInputText).
-----
line in my code:
---
<input type="text" id="txtname" runat="server">
-----
Thanks,
Mark
|
|

August 31st, 2004, 01:47 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Hey,
Well, that would be true, but I don't know what you are doing with it... Could you post any code? Actually, the simplest fix would be to change:
<input type="text" id="txtname" runat="server">
to:
<asp:TextBox id="txtname" runat="server"/>
You have the same benefits, plus it probably is better to do it this way anyway.
Brian
|
|

September 3rd, 2004, 12:43 PM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Brian,
I have it working now...
|
|
 |