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

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?

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

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.

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

simply set EnableViewState Property of textbox as FALSE

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.

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?

commented: Don't ressurect an old thread. tgreer's post is more helpful than yours. -1

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:

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

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.

And now I just realize this post is years old... thanks for bringing up the old post to complain... psh.

And now I just realize this post is years old... thanks for bringing up the old post to complain... psh.

Your direct answer helped me and probably helped others. I was overlooking that incredibly simple item, since I thought my problem was more complicated, since it involved partial-page refreshes, etc.

Being Socratic IS rude, btw, and ineffective. When I'm trying to find an answer, I don't want to wade through five pages of Socratic dialogue only to find the original question is never answered. I want a bunch of examples relating differently; the learning process is in fitting the solution to your particular problem and then understanding why.

And complaining that volunteer help does not meet your personal expectations is rude as well.

Well, I'm sorry, but if the Internet is cluttered with "volunteer help" that isn't, people end up wasting way more time than if those "volunteers" hadn't "helped" in the first place.

Well, those who are seeking help for free from others certainly have another option beyond wading through "clutter" - they can figure it out for themselves.

All of the help offered here on DaniWeb is the result of someone taking time out of their day to try and help out someone they do not know for absolutely nothing in return. It comes across as rather pathetic that you would choose to complain about the form that it took. I suppose just saying "Thanks, that helped." never crossed your mind.

All of the help offered here on DaniWeb is the result of someone taking time out of their day to try and help out someone they do not know for absolutely nothing in return. It comes across as rather pathetic that you would choose to complain about the form that it took. I suppose just saying "Thanks, that helped." never crossed your mind.

It never crossed my mind, you mean when the very first thing I said was "Your direct answer helped me and probably helped others?" OK I didn't have a thanks in there. Thanks, SheSaidImaPregy.

Or are you suggesting I say "thanks, that helped" to tgreer, whose unhelpful approach didn't help, and just outright lie?

People don't always post to help others. They could be posting to show off or to be rude, as in your case, when you called me "pathetic."

As a moderator, you ought to be *supporting* my constructive criticism of an unhelpful approach. If people on here have the impression that as long as they're not getting paid for what they say, they can be as unhelpful or sarcastic or rude as they want and still deserve thanks, they'll see a trend and become even more sarcastic, unhelpful, or rude.

If someone genuinely wants to help but has an unhelpful approach, shouldn't we as users give feedback letting them and others know that the approach wasn't helpful? Or do we have to pretend that just because they're not being paid for their posts that they helped and we should never criticise anything they say?

>People don't always post to help others. They could be posting to show off or to be rude, as in your case, when you called me "pathetic."
Do you honestly feel that you have been helpful in dragging this dead thread back up to complain? I don't see that you have added any technical value to it.

>As a moderator, you ought to be *supporting* my constructive criticism of an unhelpful approach.
I don't really believe that your reply was constructive. Criticizing a post that is three years old does not really come across as helpful and calling it 'rude and ineffective' is not what I would consider a constructive lead-in.

I also do not believe that arguing this further here is adding any value. You've stated your thoughts on it and I have stated mine. If you feel you must discuss it further, I would ask you to do so via PM. I would prefer to leave this thread open for potential future on-topic discussion.

I had the exact same problem, and none of the solutions I found here or anywhere else fixed the problem.

The solution for me was to update the values in the Page_LoadComplete instead of the Page_Load section.

Otherwise, my values kept getting overwritten. I could even update the value and do a Response.Write to see that the correct value was there, but the page still displayed the old values.

I hope this helps someone else.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.