473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 19 '05 #1
1 3111

"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 19 '05 #2

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

Similar topics

13
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
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...
1
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.,...
2
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...
4
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
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
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
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") %>'...
7
by: sphinney | last post by:
I have a datasheet style form with textbox (MyTextBox) that has the Text Format property set to "Rich Text". It is bound to a memo field in a table. How do I change the text or highlight color of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.