473,503 Members | 939 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextBox.Text value not changing when it is prepopulated

I am writing a user information update page and I populate the form on
Page_Load with the current values of the user's name, etc. When I
change the text in one of the textbox controls (e.g., change the
user's middle initial from M. to X.) and submit the form, the value
seen for middleinitial.text in the Public Sub that is executed when
the Update button is clicked is the initial value (M.) and not the new
value (X.). Is there something I need to do to make the codebehind
file see the new value and not the one set up in Page_Load?

Here are code snippets from register.aspx and register.aspx.vb. Note
that I am using Visual Studio .NET as my development tool.

Code from register.aspx:

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="register.aspx.vb" Inherits="dotNETDemo.register"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>register</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table border="0">
<tr>

<snip>

<tr>
<td>Middle Initial:
</td>
<td><asp:textbox id="MiddleInitial" runat="server"
MaxLength="2"></asp:textbox></td>
</tr>

<snip>

<tr>
<td align="middle" colSpan="2"><asp:button id="Register"
onclick="Register_Click" Runat="server"
Text="Register"></asp:button>&nbsp;&nbsp;
<asp:button id="Cancel" onclick="Cancel_Click" Runat="server"
Text="Cancel" CausesValidation="False"></asp:button></td>
</tr>
</table>
</form>
</body>
</HTML>
Code from register.aspx.vb:

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Class register
Inherits System.Web.UI.Page

<snip>

Protected WithEvents MiddleInitial As
System.Web.UI.WebControls.TextBox

<snip>

Protected WithEvents Register As System.Web.UI.WebControls.Button

<snip>
Public Sub Register_Click(ByVal sender As Object, ByVal e As
EventArgs)
' Put code to handle adding a new user here.
Dim cn As SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand
Dim prm As SqlClient.SqlParameter
Dim DBError As String
Dim UserID As Integer
Dim ReturnCode As String
Dim PersonalizationCookie As New HttpCookie("UserID")

' At this point, a Response.Write(MiddleInitial.Text) gives the
original value of "M.",
even after the value in the textbox has been changed to "X."

cn = New SqlConnection("Data Source=(local);Initial
Catalog=ArachnidWebWorks;Integrated Security=SSPI;")
cmd = New SqlCommand("spInsertNewUser", cn)
cmd.CommandType = CommandType.StoredProcedure

<remaining code to execute the sproc, etc.>

Any advice is welcome here.

Thanks,
Paul
---

Paul M. Frazier, Ph.D.
pa************@wideopenwest.com

Eschew Obfuscation!
Nov 17 '05 #1
1 8562

"Paul M. Frazier, Ph.D." <pa************@wideopenwest.com> wrote in message
news:Bn********************@wideopenwest.com...
I am writing a user information update page and I populate the form on
Page_Load with the current values of the user's name, etc. When I
change the text in one of the textbox controls (e.g., change the
user's middle initial from M. to X.) and submit the form, the value
seen for middleinitial.text in the Public Sub that is executed when
the Update button is clicked is the initial value (M.) and not the new
value (X.). Is there something I need to do to make the codebehind
file see the new value and not the one set up in Page_Load?


Page_Load is called *every* time: not only when displaying the page
originally, but also every time it's posted back (submitted).
You need to test if "IsPostBack" is true: in that case, you shouldn't
initialize your textbox...
Something like this will do:

if IsPostBack then
... initialize testbox
endif
Luc K
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
4282
by: Paul Slavin | last post by:
I have a textbox bound to a dataview, when I update the text in the textbox no changes take place in the underlying dataset. Why is this?? any answers appreciated, as to due to the underlying...
28
4292
by: kfrost | last post by:
I know this is probably simple but I have a C# form and the class for the form is called sbaSynch. I have a textbox name txtServerName. I'm creating a class to manipulate XML functions so I...
2
1181
by: Martin | last post by:
How can it be that TextBox.Text has an old value when I read it in to a variable and I can at the same time see the new value in my browser. I would guess that it has someting to do with a webpage...
1
3116
by: Paul M. Frazier, Ph.D. | last post by:
I am writing a user information update page and I populate the form on Page_Load with the current values of the user's name, etc. When I change the text in one of the textbox controls (e.g.,...
4
7373
by: MattB | last post by:
Hi. I'm working on an intranet application that requires a user to input information about themselves. I have a user control with a couple of textboxes that I want the user to enter their weight...
0
2597
by: d.steininger | last post by:
Hi there! Is there a way to bind a Textbox.Text to a ScrollBar.Value (not the Textbox-own Scrollbar) and vice versa? The Problem: I have to deal with two controls. The Textbox should accept...
16
5122
by: mj.redfox.mj | last post by:
Can anyone help? I have a textbox which I'm programatically adding by using the following code: txtTest = New TextBox txtTest.ID = "txtLeft" + cntCount.ToString...
6
2886
by: john | last post by:
I have the following textbox setup with Text & ToolTip Bindings as follows; I'm using Visual Studio 2008 VB: <asp:TextBox ID="txtDay1" runat="server" Text='<%# Eval("Day1") %>'...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.