By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,488 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

Viewstate problem with textbox values and stored procedure

P: n/a
Hi

I want to update data hold in several textbox controls on an asp.net form.
But it seems like it is the old textbox values that is "re-updates" through a
stored procedure who updates a SQL tabel. I know the SP works, because a
smalldatetime-field in the database is changed. I've tried to disable
viewstate on all textbox controls.

Any ideas to solve this problem.

Thanks.
Peter
Nov 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Textboxes automatically maintain the inputted value with or without
viewstate. My guess is that you are repopulating the textboxes with the
orignal value than updating..something like:

public Sub Page_Load
dim dr as datarow = GetInformation(x);
txtUserName.Text = dr("userName")
txtPassword.Text = dr("Password")
...
end sub

public sub SomeButton_Click()
UpdateData(txtUsername.text, txtPassword.Text)
end sub
When the page postsback Page_Load fires first and you are regetting the
information and resetting the textbox values to the old stuff, THEN the
event fires and the row is updated... The trick is to wrap the code in the
page_load in a If NOT Page.IsPostBack

of course, since you've provided no code, it's hard to tell exactly..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
Hi

I want to update data hold in several textbox controls on an asp.net form.
But it seems like it is the old textbox values that is "re-updates" through a stored procedure who updates a SQL tabel. I know the SP works, because a
smalldatetime-field in the database is changed. I've tried to disable
viewstate on all textbox controls.

Any ideas to solve this problem.

Thanks.
Peter

Nov 18 '05 #2

P: n/a
All the textboxes are populated based on a dataset result from a stored
procedure like this (only one tabel in the dataset):
For Each cRow In dsTabel.Tables("tblName").Rows
Me.ctlID.Text = cRow("ID").ToString
and so on....

When I want to update all the values from the textboxes back through another
stored procedure I do it like this:

MyConn.Open()
SQL = "ProcSomeName"
Dim MyCmd As New SqlCommand(SQL, MyConn)
MyCmd.CommandType = CommandType.StoredProcedure
MyCmd.Parameters.Add("@ID", SqlDbType.Int).Value = Me.ctlID.Text
and so on for all the textboxes .....

I use a SqlDataReader to execute the stored procedure like this:
Dim Reader As SqlDataReader
Reader = MyCmd.ExecuteReader()

The Sub doing this update it allready wrapped in "If Not Page.IsPostBack
Then". As mention does the execution of the SP works because a date-field in
the SQL tabel is updated when the Update buttom is used.

Peter
"Karl Seguin" wrote:
Textboxes automatically maintain the inputted value with or without
viewstate. My guess is that you are repopulating the textboxes with the
orignal value than updating..something like:

public Sub Page_Load
dim dr as datarow = GetInformation(x);
txtUserName.Text = dr("userName")
txtPassword.Text = dr("Password")
...
end sub

public sub SomeButton_Click()
UpdateData(txtUsername.text, txtPassword.Text)
end sub
When the page postsback Page_Load fires first and you are regetting the
information and resetting the textbox values to the old stuff, THEN the
event fires and the row is updated... The trick is to wrap the code in the
page_load in a If NOT Page.IsPostBack

of course, since you've provided no code, it's hard to tell exactly..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
Hi

I want to update data hold in several textbox controls on an asp.net form.
But it seems like it is the old textbox values that is "re-updates"

through a
stored procedure who updates a SQL tabel. I know the SP works, because a
smalldatetime-field in the database is changed. I've tried to disable
viewstate on all textbox controls.

Any ideas to solve this problem.

Thanks.
Peter


Nov 18 '05 #3

P: n/a
The problem isn't with the update code being in the if statement, it's with
the for each statement...my guess, without seeing more of your code is still
that:
For Each cRow In dsTabel.Tables("tblName").Rows
Me.ctlID.Text = cRow("ID").ToString
...
next
gets executed when the page postback...and that this would happen before the
update does, thus overwriting what the user entered with the old values from
the dataset.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
All the textboxes are populated based on a dataset result from a stored
procedure like this (only one tabel in the dataset):
For Each cRow In dsTabel.Tables("tblName").Rows
Me.ctlID.Text = cRow("ID").ToString
and so on....

When I want to update all the values from the textboxes back through another stored procedure I do it like this:

MyConn.Open()
SQL = "ProcSomeName"
Dim MyCmd As New SqlCommand(SQL, MyConn)
MyCmd.CommandType = CommandType.StoredProcedure
MyCmd.Parameters.Add("@ID", SqlDbType.Int).Value = Me.ctlID.Text
and so on for all the textboxes .....

I use a SqlDataReader to execute the stored procedure like this:
Dim Reader As SqlDataReader
Reader = MyCmd.ExecuteReader()

The Sub doing this update it allready wrapped in "If Not Page.IsPostBack
Then". As mention does the execution of the SP works because a date-field in the SQL tabel is updated when the Update buttom is used.

Peter
"Karl Seguin" wrote:
Textboxes automatically maintain the inputted value with or without
viewstate. My guess is that you are repopulating the textboxes with the
orignal value than updating..something like:

public Sub Page_Load
dim dr as datarow = GetInformation(x);
txtUserName.Text = dr("userName")
txtPassword.Text = dr("Password")
...
end sub

public sub SomeButton_Click()
UpdateData(txtUsername.text, txtPassword.Text)
end sub
When the page postsback Page_Load fires first and you are regetting the
information and resetting the textbox values to the old stuff, THEN the
event fires and the row is updated... The trick is to wrap the code in the page_load in a If NOT Page.IsPostBack

of course, since you've provided no code, it's hard to tell exactly..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
Hi

I want to update data hold in several textbox controls on an asp.net form. But it seems like it is the old textbox values that is "re-updates"

through a
stored procedure who updates a SQL tabel. I know the SP works, because a smalldatetime-field in the database is changed. I've tried to disable
viewstate on all textbox controls.

Any ideas to solve this problem.

Thanks.
Peter


Nov 18 '05 #4

P: n/a
I think you're right. I have now wrapped the call in the Page_Load event for
the Private Sub (FillVauesInTextBoxes), that based on a Stored Proc/Dataset
populates the textboxes, like this:

If Not Page.IsPostBack Then
Dim ID As String = Request.QueryString("ID")
FillValuesInTextBoxes(ID)
End If

But now I get a runtime error - stating that a the inputstring was not in
the right format - stopping at the line "Reader - MyCmd.ExecuteReader()". The
new question must be - is the SqlDataReader the wrong way to execute a
parameterized Stored Proc call in this situation.

Peter
"Karl Seguin" wrote:
The problem isn't with the update code being in the if statement, it's with
the for each statement...my guess, without seeing more of your code is still
that:
For Each cRow In dsTabel.Tables("tblName").Rows
Me.ctlID.Text = cRow("ID").ToString
...
next
gets executed when the page postback...and that this would happen before the
update does, thus overwriting what the user entered with the old values from
the dataset.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
All the textboxes are populated based on a dataset result from a stored
procedure like this (only one tabel in the dataset):
For Each cRow In dsTabel.Tables("tblName").Rows
Me.ctlID.Text = cRow("ID").ToString
and so on....

When I want to update all the values from the textboxes back through

another
stored procedure I do it like this:

MyConn.Open()
SQL = "ProcSomeName"
Dim MyCmd As New SqlCommand(SQL, MyConn)
MyCmd.CommandType = CommandType.StoredProcedure
MyCmd.Parameters.Add("@ID", SqlDbType.Int).Value = Me.ctlID.Text
and so on for all the textboxes .....

I use a SqlDataReader to execute the stored procedure like this:
Dim Reader As SqlDataReader
Reader = MyCmd.ExecuteReader()

The Sub doing this update it allready wrapped in "If Not Page.IsPostBack
Then". As mention does the execution of the SP works because a date-field

in
the SQL tabel is updated when the Update buttom is used.

Peter
"Karl Seguin" wrote:
Textboxes automatically maintain the inputted value with or without
viewstate. My guess is that you are repopulating the textboxes with the
orignal value than updating..something like:

public Sub Page_Load
dim dr as datarow = GetInformation(x);
txtUserName.Text = dr("userName")
txtPassword.Text = dr("Password")
...
end sub

public sub SomeButton_Click()
UpdateData(txtUsername.text, txtPassword.Text)
end sub
When the page postsback Page_Load fires first and you are regetting the
information and resetting the textbox values to the old stuff, THEN the
event fires and the row is updated... The trick is to wrap the code in the page_load in a If NOT Page.IsPostBack

of course, since you've provided no code, it's hard to tell exactly..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
> Hi
>
> I want to update data hold in several textbox controls on an asp.net form. > But it seems like it is the old textbox values that is "re-updates"
through a
> stored procedure who updates a SQL tabel. I know the SP works, because a > smalldatetime-field in the database is changed. I've tried to disable
> viewstate on all textbox controls.
>
> Any ideas to solve this problem.
>
> Thanks.
> Peter


Nov 18 '05 #5

P: n/a
Peter,
SqlDataReader is fine. Purist would probably tell you that you shouldn't be
returning an SqlDataReader from your data layer to your presentation
layer...and instead use either typed datasets (yack, not much better) or
custom business objects. I'm such a purist, but for now we'll skip over
that issue.

Taking off my purist hat, there's nothing wrong with what you are trying to
do. I imagine it's just a small error..nothing fundamental to your
architecture. Again, you've provided very little code to go on, so I can't
provide any guesses as to what the problem is. The only thing I can suggest
is that maybe ID is null or something or not what you are
expecting...dunno...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
I think you're right. I have now wrapped the call in the Page_Load event for the Private Sub (FillVauesInTextBoxes), that based on a Stored Proc/Dataset populates the textboxes, like this:

If Not Page.IsPostBack Then
Dim ID As String = Request.QueryString("ID")
FillValuesInTextBoxes(ID)
End If

But now I get a runtime error - stating that a the inputstring was not in
the right format - stopping at the line "Reader - MyCmd.ExecuteReader()". The new question must be - is the SqlDataReader the wrong way to execute a
parameterized Stored Proc call in this situation.

Peter
"Karl Seguin" wrote:
The problem isn't with the update code being in the if statement, it's with the for each statement...my guess, without seeing more of your code is still that:
For Each cRow In dsTabel.Tables("tblName").Rows
Me.ctlID.Text = cRow("ID").ToString
...
next
gets executed when the page postback...and that this would happen before the update does, thus overwriting what the user entered with the old values from the dataset.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
All the textboxes are populated based on a dataset result from a stored procedure like this (only one tabel in the dataset):
For Each cRow In dsTabel.Tables("tblName").Rows
Me.ctlID.Text = cRow("ID").ToString
and so on....

When I want to update all the values from the textboxes back through

another
stored procedure I do it like this:

MyConn.Open()
SQL = "ProcSomeName"
Dim MyCmd As New SqlCommand(SQL, MyConn)
MyCmd.CommandType = CommandType.StoredProcedure
MyCmd.Parameters.Add("@ID", SqlDbType.Int).Value = Me.ctlID.Text
and so on for all the textboxes .....

I use a SqlDataReader to execute the stored procedure like this:
Dim Reader As SqlDataReader
Reader = MyCmd.ExecuteReader()

The Sub doing this update it allready wrapped in "If Not Page.IsPostBack Then". As mention does the execution of the SP works because a date-field
in
the SQL tabel is updated when the Update buttom is used.

Peter
"Karl Seguin" wrote:

> Textboxes automatically maintain the inputted value with or without
> viewstate. My guess is that you are repopulating the textboxes with
the > orignal value than updating..something like:
>
> public Sub Page_Load
> dim dr as datarow = GetInformation(x);
> txtUserName.Text = dr("userName")
> txtPassword.Text = dr("Password")
> ...
> end sub
>
> public sub SomeButton_Click()
> UpdateData(txtUsername.text, txtPassword.Text)
> end sub
>
>
> When the page postsback Page_Load fires first and you are regetting the > information and resetting the textbox values to the old stuff, THEN the > event fires and the row is updated... The trick is to wrap the code in the
> page_load in a If NOT Page.IsPostBack
>
> of course, since you've provided no code, it's hard to tell
exactly.. >
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
> news:5A**********************************@microsof t.com...
> > Hi
> >
> > I want to update data hold in several textbox controls on an asp.net form.
> > But it seems like it is the old textbox values that is
"re-updates" > through a
> > stored procedure who updates a SQL tabel. I know the SP works, because a
> > smalldatetime-field in the database is changed. I've tried to

disable > > viewstate on all textbox controls.
> >
> > Any ideas to solve this problem.
> >
> > Thanks.
> > Peter
>
>
>


Nov 18 '05 #6

P: n/a
Again, you're right. If I set the visible property of the ID textbox to true
- then it works!! Is the value of the ID-textbox not available if the textbox
is invisible?

Peter

"Karl Seguin" wrote:
Peter,
SqlDataReader is fine. Purist would probably tell you that you shouldn't be
returning an SqlDataReader from your data layer to your presentation
layer...and instead use either typed datasets (yack, not much better) or
custom business objects. I'm such a purist, but for now we'll skip over
that issue.

Taking off my purist hat, there's nothing wrong with what you are trying to
do. I imagine it's just a small error..nothing fundamental to your
architecture. Again, you've provided very little code to go on, so I can't
provide any guesses as to what the problem is. The only thing I can suggest
is that maybe ID is null or something or not what you are
expecting...dunno...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
I think you're right. I have now wrapped the call in the Page_Load event

for
the Private Sub (FillVauesInTextBoxes), that based on a Stored

Proc/Dataset
populates the textboxes, like this:

If Not Page.IsPostBack Then
Dim ID As String = Request.QueryString("ID")
FillValuesInTextBoxes(ID)
End If

But now I get a runtime error - stating that a the inputstring was not in
the right format - stopping at the line "Reader - MyCmd.ExecuteReader()".

The
new question must be - is the SqlDataReader the wrong way to execute a
parameterized Stored Proc call in this situation.

Peter
"Karl Seguin" wrote:
The problem isn't with the update code being in the if statement, it's with the for each statement...my guess, without seeing more of your code is still that:
For Each cRow In dsTabel.Tables("tblName").Rows
Me.ctlID.Text = cRow("ID").ToString
...
next
gets executed when the page postback...and that this would happen before the update does, thus overwriting what the user entered with the old values from the dataset.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
> All the textboxes are populated based on a dataset result from a stored > procedure like this (only one tabel in the dataset):
> For Each cRow In dsTabel.Tables("tblName").Rows
> Me.ctlID.Text = cRow("ID").ToString
> and so on....
>
> When I want to update all the values from the textboxes back through
another
> stored procedure I do it like this:
>
> MyConn.Open()
> SQL = "ProcSomeName"
> Dim MyCmd As New SqlCommand(SQL, MyConn)
> MyCmd.CommandType = CommandType.StoredProcedure
> MyCmd.Parameters.Add("@ID", SqlDbType.Int).Value = Me.ctlID.Text
> and so on for all the textboxes .....
>
> I use a SqlDataReader to execute the stored procedure like this:
> Dim Reader As SqlDataReader
> Reader = MyCmd.ExecuteReader()
>
> The Sub doing this update it allready wrapped in "If Not Page.IsPostBack > Then". As mention does the execution of the SP works because a date-field in
> the SQL tabel is updated when the Update buttom is used.
>
> Peter
>
>
> "Karl Seguin" wrote:
>
> > Textboxes automatically maintain the inputted value with or without
> > viewstate. My guess is that you are repopulating the textboxes with the > > orignal value than updating..something like:
> >
> > public Sub Page_Load
> > dim dr as datarow = GetInformation(x);
> > txtUserName.Text = dr("userName")
> > txtPassword.Text = dr("Password")
> > ...
> > end sub
> >
> > public sub SomeButton_Click()
> > UpdateData(txtUsername.text, txtPassword.Text)
> > end sub
> >
> >
> > When the page postsback Page_Load fires first and you are regetting the > > information and resetting the textbox values to the old stuff, THEN the > > event fires and the row is updated... The trick is to wrap the code in the
> > page_load in a If NOT Page.IsPostBack
> >
> > of course, since you've provided no code, it's hard to tell exactly.. > >
> > Karl
> >
> > --
> > MY ASP.Net tutorials
> > http://www.openmymind.net/
> >
> >
> > "Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
> > news:5A**********************************@microsof t.com...
> > > Hi
> > >
> > > I want to update data hold in several textbox controls on an asp.net form.
> > > But it seems like it is the old textbox values that is "re-updates" > > through a
> > > stored procedure who updates a SQL tabel. I know the SP works, because a
> > > smalldatetime-field in the database is changed. I've tried to disable > > > viewstate on all textbox controls.
> > >
> > > Any ideas to solve this problem.
> > >
> > > Thanks.
> > > Peter
> >
> >
> >


Nov 18 '05 #7

P: n/a
uhmm..didn't think so....

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
Again, you're right. If I set the visible property of the ID textbox to true - then it works!! Is the value of the ID-textbox not available if the textbox is invisible?

Peter

"Karl Seguin" wrote:
Peter,
SqlDataReader is fine. Purist would probably tell you that you shouldn't be returning an SqlDataReader from your data layer to your presentation
layer...and instead use either typed datasets (yack, not much better) or
custom business objects. I'm such a purist, but for now we'll skip over
that issue.

Taking off my purist hat, there's nothing wrong with what you are trying to do. I imagine it's just a small error..nothing fundamental to your
architecture. Again, you've provided very little code to go on, so I can't provide any guesses as to what the problem is. The only thing I can suggest is that maybe ID is null or something or not what you are
expecting...dunno...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
I think you're right. I have now wrapped the call in the Page_Load event
for
the Private Sub (FillVauesInTextBoxes), that based on a Stored

Proc/Dataset
populates the textboxes, like this:

If Not Page.IsPostBack Then
Dim ID As String = Request.QueryString("ID")
FillValuesInTextBoxes(ID)
End If

But now I get a runtime error - stating that a the inputstring was not
in the right format - stopping at the line "Reader - MyCmd.ExecuteReader()". The
new question must be - is the SqlDataReader the wrong way to execute a
parameterized Stored Proc call in this situation.

Peter
"Karl Seguin" wrote:

> The problem isn't with the update code being in the if statement,
it's with
> the for each statement...my guess, without seeing more of your code
is still
> that:
> For Each cRow In dsTabel.Tables("tblName").Rows
> Me.ctlID.Text = cRow("ID").ToString
> ...
> next
> gets executed when the page postback...and that this would happen
before the
> update does, thus overwriting what the user entered with the old
values from
> the dataset.
>
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in message
> news:EE**********************************@microsof t.com...
> > All the textboxes are populated based on a dataset result from a

stored
> > procedure like this (only one tabel in the dataset):
> > For Each cRow In dsTabel.Tables("tblName").Rows
> > Me.ctlID.Text = cRow("ID").ToString
> > and so on....
> >
> > When I want to update all the values from the textboxes back
through > another
> > stored procedure I do it like this:
> >
> > MyConn.Open()
> > SQL = "ProcSomeName"
> > Dim MyCmd As New SqlCommand(SQL, MyConn)
> > MyCmd.CommandType = CommandType.StoredProcedure
> > MyCmd.Parameters.Add("@ID", SqlDbType.Int).Value = Me.ctlID.Text
> > and so on for all the textboxes .....
> >
> > I use a SqlDataReader to execute the stored procedure like this:
> > Dim Reader As SqlDataReader
> > Reader = MyCmd.ExecuteReader()
> >
> > The Sub doing this update it allready wrapped in "If Not

Page.IsPostBack
> > Then". As mention does the execution of the SP works because a

date-field
> in
> > the SQL tabel is updated when the Update buttom is used.
> >
> > Peter
> >
> >
> > "Karl Seguin" wrote:
> >
> > > Textboxes automatically maintain the inputted value with or without > > > viewstate. My guess is that you are repopulating the textboxes with the
> > > orignal value than updating..something like:
> > >
> > > public Sub Page_Load
> > > dim dr as datarow = GetInformation(x);
> > > txtUserName.Text = dr("userName")
> > > txtPassword.Text = dr("Password")
> > > ...
> > > end sub
> > >
> > > public sub SomeButton_Click()
> > > UpdateData(txtUsername.text, txtPassword.Text)
> > > end sub
> > >
> > >
> > > When the page postsback Page_Load fires first and you are
regetting the
> > > information and resetting the textbox values to the old stuff,
THEN the
> > > event fires and the row is updated... The trick is to wrap the
code in
> the
> > > page_load in a If NOT Page.IsPostBack
> > >
> > > of course, since you've provided no code, it's hard to tell

exactly..
> > >
> > > Karl
> > >
> > > --
> > > MY ASP.Net tutorials
> > > http://www.openmymind.net/
> > >
> > >
> > > "Peter D.C." <Peter D.C.@discussions.microsoft.com> wrote in

message > > > news:5A**********************************@microsof t.com...
> > > > Hi
> > > >
> > > > I want to update data hold in several textbox controls on an

asp.net
> form.
> > > > But it seems like it is the old textbox values that is

"re-updates"
> > > through a
> > > > stored procedure who updates a SQL tabel. I know the SP works,

because
> a
> > > > smalldatetime-field in the database is changed. I've tried to

disable
> > > > viewstate on all textbox controls.
> > > >
> > > > Any ideas to solve this problem.
> > > >
> > > > Thanks.
> > > > Peter
> > >
> > >
> > >
>
>
>


Nov 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.