Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 April 18th, 2005, 10:56 PM
Registered User
 
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP.NET TextBox Control Dilema

Hi everyone.

I am currently working on a ASP/VB.NET app and I am having an issue with ASP.NET forms and the submission of them. I am currently using a TextControl in an ASPX page and when I try and populate this field with a value, the value appears HOWEVER if a user changes this value in the Text input type and re-submits the form the OLDER default value is sent to the SERVER. In standard HTML/ASP setting a value property of an text input box still did not prevent users from over-riding it on submission of a form.


Example Code:

''''TextControl in my ASPX page

<asp:TextBox ID="txtName" Runat="server" width="200px" />


''''From within an ASPX.VB page I set the control's Text attribute

txtName.Text = "John"


When the ASPX page loads the default value is pre-loaded as "John". Exactly what I want HOWEVER the issue I am having is when someone changes this value and re-submits the FORM the value is not getting passed in its changed form. Every submission passes a txtName.Text value of "John"!

Any help or ideas would be greatly appreciated.

Regards,

J
 
Old April 18th, 2005, 11:33 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

It is because you are setting the textbox value as John in Page_Load.Remove that line and set the initial value in the <asp:textbox> tag itself.

 
Old April 19th, 2005, 12:02 AM
Registered User
 
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Santhi
 It is because you are setting the textbox value as John in Page_Load.Remove that line and set the initial value in the <asp:textbox> tag itself.

Hmmm no I am thinking.

Being a former ASP programer moving to ASP.Net has been a challenge.
Considering the page I am loading is totally dynamic how do I set the value within the textbox itself.
<asp:TextBox ID="txtName" Runat="server" width="200px">John</asp:TextBox> sounds simply however my next question is how do I pass in string "John", I tried passing it by a Label Control i.e. forcing a server populated Label control in between the TextBox control. This results in an error.

You mention to: set the initial value in the <asp:textbox> tag itself.

Can you show me a code snippet? Presently I have managed to solve my problem using JavaScript and the Javascript onLoad event, but my preference would be to get this working MINUS the Javascript.

Thanks again.

 
Old April 19th, 2005, 12:38 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

Hi find below my code snippet
<asp:TextBox ID="txtName" Runat="server" Text="John" width="200px"></asp:TextBox>

 
Old April 19th, 2005, 08:13 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

j,

The problem is where you are setting the default value. Chances are pretty good that the assignment is happening every time the page runs. This is what's causing the default to override the user value. The user values are processed after the page is built but before the Load event. So basically anyplace in the page where you'd make that assignment will override the user modified value.

You have a couple options:
1. Use what Santhi has described: set the default in the markup. This way, the user value will get accepted when the page posts back.

2. Wrap your default assignment in:
  If Not IsPostback Then ...
This will result in only setting your default value on the initial page hit and not subsequent postbacks.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I set TextBox value from asp.net Listbox, vishnu108mishra ASP.NET 2.0 Professional 1 March 10th, 2008 06:11 AM
using asp.net web user control in asp 3.0 App i_shahid Classic ASP Professional 0 January 8th, 2008 07:32 AM
Text Formating in ASP.Net Textbox aliirfan84 ASP.NET 2.0 Professional 4 May 25th, 2007 03:04 AM
unable to display stored data in textbox(asp.net) Abhinav_jain_mca ADO.NET 6 August 4th, 2004 07:45 AM
unable to print stored data in textbox(asp.net) Abhinav_jain_mca ADO.NET 1 July 30th, 2004 09:34 PM





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