Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Postback not working, pages not maintaining state - I entirely don't get it.

Reply
Thread Tools

Postback not working, pages not maintaining state - I entirely don't get it.

 
 
Tom wilson
Guest
Posts: n/a
 
      02-11-2005
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.


 
Reply With Quote
 
 
 
 
Norman Yuan
Guest
Posts: n/a
 
      02-11-2005
if you ever read a piece of sample code on ASP.NET, you will notice that
almost all Page_Load() event handler has a line of code like this:

Private Sub Page_Load()

If Not Page.IsPostBack Then
BuildPage() 'You only need to dynamically biuld the page when the
page is called the first time
Else
'Do something else if necessary when the page is posted back
'Or do nothing, leave processing to other server event handler, such
as Button_Click, DropDownList_SelectedIndexChanged...
End If

End Sub

"Tom wilson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
 
 
 
Tom wilson
Guest
Posts: n/a
 
      02-11-2005
Oh yes, I've tried that:

Private Sub Page_Load(...
if Me.IsPostBack = False Then
BuildPage()
end if
end sub

The results:

1 - Load the page, fill out, submit.
2 - Blank page.



On Fri, 11 Feb 2005 12:54:58 -0700, "Norman Yuan"
<(E-Mail Removed)> wrote:

>if you ever read a piece of sample code on ASP.NET, you will notice that
>almost all Page_Load() event handler has a line of code like this:
>
>Private Sub Page_Load()
>
> If Not Page.IsPostBack Then
> BuildPage() 'You only need to dynamically biuld the page when the
>page is called the first time
> Else
> 'Do something else if necessary when the page is posted back
> 'Or do nothing, leave processing to other server event handler, such
>as Button_Click, DropDownList_SelectedIndexChanged...
> End If
>
>End Sub
>
>"Tom wilson" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
>> 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.
>>
>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui Python 0 04-27-2009 12:46 PM
Dropdown is maintaining itz state after postback =?Utf-8?B?RGVlcHNvbiBUaG9tYXM=?= ASP .Net 1 06-01-2006 02:58 PM
Dropdown is not maintaining itz state after postback =?Utf-8?B?RGVlcHNvbiBUaG9tYXM=?= ASP .Net 5 05-31-2006 06:03 AM
Postback not working, Pages not maintaining state Tom wilson ASP .Net 2 02-14-2005 06:00 PM
maintaining state for dynamic controls between PostBack() ??? muzzy ASP .Net Web Controls 1 11-07-2003 12:33 PM



Advertisments