| | |
Textbox is not losing its previous value
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2005
Posts: 15
Reputation:
Solved Threads: 0
I hav a program with 2 textboxes in which I hav to display data fields from sql tables and insert values in to table through these 2 textboxes.
the program goes like this
Dim ds As New DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
da.Fill(ds, "ramtable")
Dim rno As Byte
rno = 0
call filldata(rno)
End Sub
Private Sub filldata(ByVal r1 As Byte)
t1.Text = ds.Tables("ramtable").Rows(r1).Item(0) textbox1 filled for the first time with value in sql table (suppose "abc"
t2.Text = ds.Tables("ramtable").Rows(r1).Item(1)
End Sub
Private Sub upd_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles upd_btn.Click
Dim r As DataRow
r = ds.Tables("ramtable").NewRow
r.Item(0) = Val(t1.Text) here the new value is inserted into textbox1 which will be taken into sql but this value remains "abc"(previously filled one) so I m getting error while updating as value already exist
r.Item(1) = t2.Text
ds.Tables("ramtable").Rows.Add(r)
da.Update(ds, "ramtable")
t1.Text = ""
t2.Text = ""
End Sub
so why the value of textbox1 is not changing even if I have changed it in the web form
the program goes like this
Dim ds As New DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
da.Fill(ds, "ramtable")
Dim rno As Byte
rno = 0
call filldata(rno)
End Sub
Private Sub filldata(ByVal r1 As Byte)
t1.Text = ds.Tables("ramtable").Rows(r1).Item(0) textbox1 filled for the first time with value in sql table (suppose "abc"
t2.Text = ds.Tables("ramtable").Rows(r1).Item(1)
End Sub
Private Sub upd_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles upd_btn.Click
Dim r As DataRow
r = ds.Tables("ramtable").NewRow
r.Item(0) = Val(t1.Text) here the new value is inserted into textbox1 which will be taken into sql but this value remains "abc"(previously filled one) so I m getting error while updating as value already exist
r.Item(1) = t2.Text
ds.Tables("ramtable").Rows.Add(r)
da.Update(ds, "ramtable")
t1.Text = ""
t2.Text = ""
End Sub
so why the value of textbox1 is not changing even if I have changed it in the web form
•
•
Join Date: Mar 2006
Posts: 1
Reputation:
Solved Threads: 0
so how do you think the textbox value should be updated if it is a server control.
The sequence of my actions is:
1. Webserver control - textboxes get their text by a stored procedure call.
2. The textbox is editable and the user can change the textbox.text value
3. I need to get the value from step 2 and update database
Please advise.
Thanks in advance
The sequence of my actions is:
1. Webserver control - textboxes get their text by a stored procedure call.
2. The textbox is editable and the user can change the textbox.text value
3. I need to get the value from step 2 and update database
Please advise.
Thanks in advance
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
When the user submits the form, the values from the form will be inside the Response object. You can get the values there, if you like.
The ASP.NET Page Lifecycle goes through a series of discrete steps, well-documented on my site and elsewhere on the web.
Any static web controls, meaning, those controls that you built into the page via the Visual Studio toolbox/designer, are re-created, and the values from the Response object bound to them as part of the LoadPostBackData stage in the lifecycle.
If these textboxes are dynamically created, via some server-side event procedure, then the controls need to be re-created, by you, in every code path that might need them and their values, prior to the LoadPostBackData stage, so that they can be properly bound.
Thus my original question, which you never answered and isn't displayed in your code:
So... where are these textboxes actually created?
Also, examine your code-path. How are you preventing your step "1" from occuring when the user submits the form? From the code you posted, evidently you're calling "filldata" on Page_Load. Thus, everytime you run your code, you're going to ignore what the user entered, and instead go get what's currently in the database. I hinted at that in my first response, as well.
Before I can help any further, you need to re-read and think through the answers you've already been given.
The ASP.NET Page Lifecycle goes through a series of discrete steps, well-documented on my site and elsewhere on the web.
Any static web controls, meaning, those controls that you built into the page via the Visual Studio toolbox/designer, are re-created, and the values from the Response object bound to them as part of the LoadPostBackData stage in the lifecycle.
If these textboxes are dynamically created, via some server-side event procedure, then the controls need to be re-created, by you, in every code path that might need them and their values, prior to the LoadPostBackData stage, so that they can be properly bound.
Thus my original question, which you never answered and isn't displayed in your code:
So... where are these textboxes actually created?
Also, examine your code-path. How are you preventing your step "1" from occuring when the user submits the form? From the code you posted, evidently you're calling "filldata" on Page_Load. Thus, everytime you run your code, you're going to ignore what the user entered, and instead go get what's currently in the database. I hinted at that in my first response, as well.
Before I can help any further, you need to re-read and think through the answers you've already been given.
•
•
Join Date: Nov 2007
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
When the user submits the form, the values from the form will be inside the Response object. You can get the values there, if you like.
blah blah blah blah
Most developers are under time restraints, and a straight out answer to his question will be absorbed and remembered by the guy.
But NO, you have to be rude and condensending.
Wonder if you ever remember when you were a newbie?
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
Hey buddie, you need to put your first part of your data within an IsPostBack portion. The reason why it is becoming the old data is that when you postback to the server, it still refreshes the page which plays page_Load once again, where you set the t1 and t2 values. So they are being reset. You need to put your page_load information into a Page.IsPostBack statement:
Now the page_load information doesn't re-execute when you postback to the server, which keeps your information in the textboxes.
If you have any questions, don't hesitate to PM me.
ASP.NET Syntax (Toggle Plain Text)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack then da.Fill(ds, "ramtable") Dim rno As Byte rno = 0 call filldata(rno) End If End Sub
If you have any questions, don't hesitate to PM me.
Last edited by SheSaidImaPregy; Feb 8th, 2008 at 5:34 pm.
![]() |
Similar Threads
- Unwanted data injected into datagrid textbox (ASP.NET)
- Deleting TextBox'es cause application losing foucs (C#)
- Accessing recent posts. (DaniWeb Community Feedback)
Other Threads in the ASP.NET Forum
- Previous Thread: file upload
- Next Thread: XML documents and display on a datagrid
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 activexcontrol advice ajax alltypeofvideos anathor application asp asp.net bc30451 bottomasp.net box browser button c# checkbox click commonfunctions confirmationcodegeneration css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dynamically edit expose feedback fileuploader fill flash form formatdecimal forms formview google grid gridview gudi iframe iis javascript jquery listbox login microsoft mono mouse mssql multistepregistration news numerical objects opera panelmasterpagebuttoncontrols parent project radio redirect registration relationaldatabases reportemail richtextbox rotatepage save schoolproject search security select silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos view virtualdirectory vista visualstudio web webapplications webdevelopemnt webprogramming webservice xsl youareanotmemberofthedebuggerusers






