943,987 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 15812
  • ASP.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
May 19th, 2005
0

Textbox is not losing its previous value

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ramareddy_dotne is offline Offline
15 posts
since May 2005
May 19th, 2005
0

Re: Textbox is not losing its previous value

So... where are these textboxes actually created? Are they WebServer controls, or just HTML "input" fields?

If they are Webserver controls, ask yourself why?

If they aren't, then get the values out of the Response object.

When is "filldata" executed?
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Mar 14th, 2006
0

Re: Textbox is not losing its previous value

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ruchiumb is offline Offline
1 posts
since Mar 2006
Mar 14th, 2006
1

Re: Textbox is not losing its previous value

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.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Apr 3rd, 2006
0

Re: Textbox is not losing its previous value

in case any newbie like me encounter this problem and dont understand the above hints
the solution is....


Private Sub Page_Load(....)
'Put user code to initialize the page here

...
...
'only load data into textbox when the page is first load
If Not (Page.IsPostBack)
{
call filldata(...)
}

End Sub
Reputation Points: 10
Solved Threads: 0
Newbie Poster
y2kstephen is offline Offline
1 posts
since Apr 2006
Aug 23rd, 2006
0

Re: Textbox is not losing its previous value

simply set EnableViewState Property of textbox as FALSE
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nunnakk is offline Offline
4 posts
since Aug 2006
Aug 23rd, 2006
0

Re: Textbox is not losing its previous value

That is not a correct answer. ViewState doesn't have anything to do with the value of HTML form objects and their corresponding server controls, only with the state of certain server controls that do not render as HTML Form objects.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Feb 8th, 2008
-2

Re: Textbox is not losing its previous value

Click to Expand / Collapse  Quote originally posted by tgreer ...
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
I must say, your strategy of being Socratic with your assistance is rude.
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?
Reputation Points: 9
Solved Threads: 0
Newbie Poster
crystal9154 is offline Offline
1 posts
since Nov 2007
Feb 8th, 2008
0

Re: Textbox is not losing its previous value

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:
ASP.NET Syntax (Toggle Plain Text)
  1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. If Not Page.IsPostBack then
  3. da.Fill(ds, "ramtable")
  4. Dim rno As Byte
  5. rno = 0
  6. call filldata(rno)
  7. End If
  8. End Sub
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.
Last edited by SheSaidImaPregy; Feb 8th, 2008 at 5:34 pm.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Feb 8th, 2008
0

Re: Textbox is not losing its previous value

And now I just realize this post is years old... thanks for bringing up the old post to complain... psh.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: file upload
Next Thread in ASP.NET Forum Timeline: XML documents and display on a datagrid





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC