Textbox is not losing its previous value

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2005
Posts: 15
Reputation: ramareddy_dotne is an unknown quantity at this point 
Solved Threads: 0
ramareddy_dotne ramareddy_dotne is offline Offline
Newbie Poster

Textbox is not losing its previous value

 
0
  #1
May 19th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Textbox is not losing its previous value

 
0
  #2
May 19th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 1
Reputation: ruchiumb is an unknown quantity at this point 
Solved Threads: 0
ruchiumb ruchiumb is offline Offline
Newbie Poster

Re: Textbox is not losing its previous value

 
0
  #3
Mar 14th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Textbox is not losing its previous value

 
1
  #4
Mar 14th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 1
Reputation: y2kstephen is an unknown quantity at this point 
Solved Threads: 0
y2kstephen y2kstephen is offline Offline
Newbie Poster

Re: Textbox is not losing its previous value

 
0
  #5
Apr 3rd, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 4
Reputation: nunnakk is an unknown quantity at this point 
Solved Threads: 0
nunnakk nunnakk is offline Offline
Newbie Poster

Re: Textbox is not losing its previous value

 
0
  #6
Aug 23rd, 2006
simply set EnableViewState Property of textbox as FALSE
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Textbox is not losing its previous value

 
0
  #7
Aug 23rd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 1
Reputation: crystal9154 is an unknown quantity at this point 
Solved Threads: 0
crystal9154 crystal9154 is offline Offline
Newbie Poster

Re: Textbox is not losing its previous value

 
-2
  #8
Feb 8th, 2008
Originally Posted by tgreer View Post
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Textbox is not losing its previous value

 
0
  #9
Feb 8th, 2008
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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Textbox is not losing its previous value

 
0
  #10
Feb 8th, 2008
And now I just realize this post is years old... thanks for bringing up the old post to complain... psh.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC