Ask a Question related to ASP.NET General, Design and Development.
-
Paul M. Frazier, Ph.D. #1
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>
<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.
[email]paul_m_frazier@wideopenwest.com[/email]
Eschew Obfuscation!
Paul M. Frazier, Ph.D. Guest
-
Changing text without changing frames.
I have a small flash movie that is basically a color chooser. Rather than changing the color of an item by putting the color in a frame I change... -
Changing text to a textbox control in row 5 of a datagrid
dim txt as textbox txt=datagrid1.item(0).controls(2) txt.text=xxxxxx "William Pulling via .NET 247" <anonymous@dotnet247.com>, haber iletisinde... -
changing the size of a textbox in a datagrid?
Hi There, I would like to find out if I can modify some of the properties of a textbox within a datagrid? 1. How can modify the width of the... -
Selecting all text in a textbox?
I've got a server-side textbox that receives the focus when the page loads. It has the text "Refine your Search" in the textbox. Obviously the user... -
formatting text in textbox while typing
Hi .. did you accomplish it? If yes .. could you please inform me what should I do? I met the same problem .. many thanks in advance Best... -
Luc Kumps #2
Re: TextBox.Text value not changing when it is prepopulated
"Paul M. Frazier, Ph.D." <paul_m_frazier@wideopenwest.com> wrote in message
news:Bn-dnTFM0MgnYrmiXTWJjQ@wideopenwest.com...Page_Load is called *every* time: not only when displaying the page> 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?
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
Luc Kumps Guest
-
Unregistered #3
Re: TextBox.Text value not changing when it is prepopulated
THANK YOU!
That one almost drove me mad, and it was that "simple". The postback replaced the entries done updating the database with the old values.Unregistered Guest
-



Reply With Quote


