473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Postback not working, Pages not maintaining state

This is a huge problem. I'm going insane. I've tried to solve this
elsewhere and no one can suggest how to make this work. To me, this
should be a very basic thing to do.

I have an asp.net application that is a survey acceptor. The site is
to display a page of survey questions and accept the responses. It
builds the entire page dynamically from SQL Server tables. The idea
is that when a person submits their responses, if there are validation
errors, to reload the page with the error text under the question
heading. I have this working. Sort of.

- There are 3 questions, all required. I load the page and answer the
first question only and hit submit.
- The error texts show up! But the question I selected (radio) isn't
selected anymore.
- I choose the first question again and hit submit. The question
remains selected but the errror texts are gone.

This goes back and forth with each click of the button; errors and
noselection, selection and no errors, errors and no selection,
selection and no errors. I'm not understanding something. Here's the
basic flow of the page:

Private Sub Page_Load
BuildPage()
End Sub

Private Sub BuildPage()
' Code to build the page from SQL Server tables.
' Creates controls, HTML elements, a submit button and a handler for
the button click.
' Also checks an array for errors and displays error text:

If Me.IsPostBack = True Then
ErrorString = CheckForError(Q.ID)
If ErrorString <> "" Then
AddLiteral(ErrorString)
End If
End If
' Question text is placed here
' Controls (ie. radios) are placed here
End Sub

Private Sub Submit_Click
' Checks for errors in the page; ie. a question has not been answered.
' Loads an array of question ID's and the errors associated

If ErrorCount > 0 then
PlaceHolder1.Controls.Clear()
BuildPage()
else
response.redirect("ThankYou.aspx")
end if

end sub

So this is how I see this:

- Load the page, build its content in Page_Load
- Fill out, Submit. The server gets the page and executes the button
click code.
- The code checks for errors. Assume there is one.
- Above, Errorcount > 0. It rebuilds the page by clearing the
Placeholder and re-adding the controls. Since this is postback, it
inserts the error texts as it builds and it gets sent back to the
client.

But that's not right somehow because although I do get the error texts
inserted, the selections I did make are cleared. When I hit submit on
this page, it comes back with my selections and no errors. I'm told
that if I build the page in Page_Init, the control states will be
maintained but they aren't.

Where is my thinking going askew?

If it helps to admit I'm a newbie to asp.net and am an idiot then
please, make that assumption. :)
Nov 19 '05 #1
3 1413
Tom wilson wrote:
This is a huge problem. I'm going insane. I've tried to solve this
elsewhere and no one can suggest how to make this work. To me, this
should be a very basic thing to do.

I have an asp.net application that is a survey acceptor. The site is
to display a page of survey questions and accept the responses. It
builds the entire page dynamically from SQL Server tables. The idea
is that when a person submits their responses, if there are validation
errors, to reload the page with the error text under the question
heading. I have this working. Sort of.

- There are 3 questions, all required. I load the page and answer the
first question only and hit submit.
- The error texts show up! But the question I selected (radio) isn't
selected anymore.
- I choose the first question again and hit submit. The question
remains selected but the errror texts are gone.

This goes back and forth with each click of the button; errors and
noselection, selection and no errors, errors and no selection,
selection and no errors. I'm not understanding something. Here's the
basic flow of the page:

Private Sub Page_Load
BuildPage()
End Sub

Private Sub BuildPage()
' Code to build the page from SQL Server tables.
' Creates controls, HTML elements, a submit button and a handler for
the button click.
' Also checks an array for errors and displays error text:

If Me.IsPostBack = True Then
ErrorString = CheckForError(Q.ID)
If ErrorString <> "" Then
AddLiteral(ErrorString)
End If
End If
' Question text is placed here
' Controls (ie. radios) are placed here
End Sub


I think the problem is that you add the literal
before you build the rest of the page.
This causes all controls on the rest of the page
to get another ID. Which causes postback to fail.
I suggest moving the If block to just before End Sub.

--

Riki
Nov 19 '05 #2

That's it.

You're right, I'm clearing the placeholder and re-creating the
controls. I added an "AddError" routine that inserts my error texts
into the placeholder order rather than rebuilding the page from
scratch. I never would have thought of that, THANKS!!!! The page
works.

Tom
On Mon, 14 Feb 2005 15:47:38 +0100, "Riki" <ri**@nospam.com> wrote:
Tom wilson wrote:
This is a huge problem. I'm going insane. I've tried to solve this
elsewhere and no one can suggest how to make this work. To me, this
should be a very basic thing to do.

I have an asp.net application that is a survey acceptor. The site is
to display a page of survey questions and accept the responses. It
builds the entire page dynamically from SQL Server tables. The idea
is that when a person submits their responses, if there are validation
errors, to reload the page with the error text under the question
heading. I have this working. Sort of.

- There are 3 questions, all required. I load the page and answer the
first question only and hit submit.
- The error texts show up! But the question I selected (radio) isn't
selected anymore.
- I choose the first question again and hit submit. The question
remains selected but the errror texts are gone.

This goes back and forth with each click of the button; errors and
noselection, selection and no errors, errors and no selection,
selection and no errors. I'm not understanding something. Here's the
basic flow of the page:

Private Sub Page_Load
BuildPage()
End Sub

Private Sub BuildPage()
' Code to build the page from SQL Server tables.
' Creates controls, HTML elements, a submit button and a handler for
the button click.
' Also checks an array for errors and displays error text:

If Me.IsPostBack = True Then
ErrorString = CheckForError(Q.ID)
If ErrorString <> "" Then
AddLiteral(ErrorString)
End If
End If
' Question text is placed here
' Controls (ie. radios) are placed here
End Sub


I think the problem is that you add the literal
before you build the rest of the page.
This causes all controls on the rest of the page
to get another ID. Which causes postback to fail.
I suggest moving the If block to just before End Sub.


Nov 19 '05 #3

That's it.

You're right, I'm clearing the placeholder and re-creating the
controls. I added an "AddError" routine that inserts my error texts
into the placeholder order rather than rebuilding the page from
scratch. I never would have thought of that, THANKS!!!! The page
works.

Tom
On Mon, 14 Feb 2005 15:47:38 +0100, "Riki" <ri**@nospam.com> wrote:
Tom wilson wrote:
This is a huge problem. I'm going insane. I've tried to solve this
elsewhere and no one can suggest how to make this work. To me, this
should be a very basic thing to do.

I have an asp.net application that is a survey acceptor. The site is
to display a page of survey questions and accept the responses. It
builds the entire page dynamically from SQL Server tables. The idea
is that when a person submits their responses, if there are validation
errors, to reload the page with the error text under the question
heading. I have this working. Sort of.

- There are 3 questions, all required. I load the page and answer the
first question only and hit submit.
- The error texts show up! But the question I selected (radio) isn't
selected anymore.
- I choose the first question again and hit submit. The question
remains selected but the errror texts are gone.

This goes back and forth with each click of the button; errors and
noselection, selection and no errors, errors and no selection,
selection and no errors. I'm not understanding something. Here's the
basic flow of the page:

Private Sub Page_Load
BuildPage()
End Sub

Private Sub BuildPage()
' Code to build the page from SQL Server tables.
' Creates controls, HTML elements, a submit button and a handler for
the button click.
' Also checks an array for errors and displays error text:

If Me.IsPostBack = True Then
ErrorString = CheckForError(Q.ID)
If ErrorString <> "" Then
AddLiteral(ErrorString)
End If
End If
' Question text is placed here
' Controls (ie. radios) are placed here
End Sub


I think the problem is that you add the literal
before you build the rest of the page.
This causes all controls on the rest of the page
to get another ID. Which causes postback to fail.
I suggest moving the If block to just before End Sub.


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Maria | last post by:
Hi I have a asp:table that I want to hold the values between postbacks. Hope some one knows how I can get that to work in an easy way. The table is loaded in runtime with different textboxes....
1
by: Novice | last post by:
Hey all, I have finally managed to create a Custom WebControl and am using a technique from another programmer to maintain state between pages - I would just like to validate this idea. ...
0
by: Justin Crossley | last post by:
I have a webform that lists search results using an XML control The search results are contained in a string called strResults and are transformed using an xsl file into formatted results. The...
6
by: Brian Miller | last post by:
I've been constructing an ASP.Net application using the 1.1 framework, and have been using Web Matrix for development purposes. Now that my application is near completion, I wanted to see if I can...
2
by: Tom wilson | last post by:
This is a huge problem. I'm going insane. I've tried to solve this elsewhere and no one can suggest how to make this work. To me, this should be a very basic thing to do. I have an asp.net...
1
by: Deepson Thomas | last post by:
Hi, Currently iam facing a strange problem.. One dropdown in my page is keeping itz state after postback. Whichever the item i selected is not the selected item after postback. it goes back to the...
5
by: Deepson Thomas | last post by:
Hi, Currently iam facing a strange problem.. One dropdown in my page is not keeping itz state after postback. Whichever the item i select irrespective of that after the post-back the default...
15
by: mc | last post by:
I'm writing an app for managing Task Lists, I'm trying to add some controls to a form that I can use to link tasks, my original intention was to: - Add two list boxes, one listing "all Tasks"...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.