Wrox Programmer Forums
|
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
 
Old August 30th, 2004, 06:32 AM
Authorized User
 
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.


 
Old August 30th, 2004, 07:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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
 
Old August 30th, 2004, 09:06 AM
Authorized User
 
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old August 30th, 2004, 02:38 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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
 
Old August 31st, 2004, 07:07 AM
Authorized User
 
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old August 31st, 2004, 11:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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
 
Old August 31st, 2004, 12:54 PM
Authorized User
 
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old August 31st, 2004, 01:47 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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
 
Old September 3rd, 2004, 12:43 PM
Authorized User
 
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Brian,

I have it working now...






Similar Threads
Thread Thread Starter Forum Replies Last Post
Cycling through all text boxes sjf905 C# 2 September 21st, 2006 12:43 AM
Rich Text Boxes speedlearner All Other Wrox Books 1 June 22nd, 2006 08:04 AM
Access VBA - Controlling Text boxes in a form Scripts82 Access VBA 4 February 8th, 2006 08:35 PM
Using integers with text boxes clojinted General .NET 1 February 19th, 2005 08:12 PM
HELP with text boxes on webpage rwheeleragco Javascript How-To 1 November 2nd, 2004 04:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.