How to save values when i click previous button in asp.net - asp.net

I have created online exam application (web based) in asp.net c#. In my application first form includes dropdownlist for tests & start button. When i select particular test from dropdownlist & after clicking to start button it goes to the next page. It includes one label for question, radiobuttonlist for answers, next & previous button.In first form in the click event of start button i have created non repeated random values ( for question ids) i.e stored in array.when it redirects to another page then 1st question from that array will display with answers & after clicking next button next question will appear, here i have inserted selected values(answers selected in radiobuttonlist) by user in database to calculate score. Problem is with previous button, when i click to previous button then it goes to previous button but i want earlier selected values by user to be bind with that radiobuttonlist. how i can do this?

I think you are storing the previous question answer in your database or somewhere else.
Then in the page_load event check the database with the question number and if the records available then display the user selection accordingly by fetching them from the database.

Related

Dropdown Selected Item Not Properly set

I have a page where The Dropdownbox (selUsers) is populated from a database on pageload.
On LoadComplete I am setting the value based on a value from the maser page.
selUsers.SelectedValue = master.intUserID
This appears to work properly, as the correct text is displayed in the dropdownbox.
I have a button that calls a sub. In that sub, hen I call selUsers.SelectedItem.Value or selUsers.SelectedValue I get the value of the first item in the dropdownbox not the selected one.
I have been reading and I am seeing that the code to set the value has to be in ispostback, but I am not posting the page back, nor do I want to. Is it truly the case that even if you set the value of the dropdown, it isn't really set until you post the page back? If that isnt the case, why am I not getting the correct value.
Before you ask, I have scoured the code, and at no place else is the dropdown being rebound, or the value being reset.
the whole page life cycle can be a tad confusing.
I'd advise you to read this (article: ASP.NET Page Life Cycle Overview) https://msdn.microsoft.com/en-us/library/ms178472.aspx
But to answer your question:
If you click that button , the following takes place in this specific order (relevant to your problem):
1) Page load event gets raised: this is where you get your data and databind, thus 'resetting' the selected value on the dropdownlist as well.
2) The button click event gets raised (this is an item event): You read out the value you want to read out
BUT since you haven't reached LoadComplete yet (where you'll set the new selected value) you'll see the first value in the list.
3) Load complete event gets raised: here you set the correct selected value.
So yes, if you click on an asp web form's button (by default), it will cause a postback and go through the whole page life cycle to build the 'response' to your action. You'll have to take this into account while building your pages.
You can see this in action while debugging: place breakpoints on those 3 points in your code behind file and then click the button.
To solve your problem, you'll need to set the selected value after you databind your dropdownlist AND before you read out the selected value.
Hope this helps.

Combo box refresh after click button event

I have a combobox binded to a stored procedure which pulls in Years
the click event button deletes whichever year is selected and that works as I can confirm the record is actually deleted on the back end in the database. But after the delete the combo box doesnt refresh and still shows the old record. Any ideas?
You need to query the data again and call combo.DataBind() or delete the item yourself.

Regarding to save previous record in asp.net

Hi
I have one label for question, radiobuttonlist for their answers, next button to move next question & previous button. I am displaying one question per page after clicking next button next question appears, but when i click previous button previous question appears.
But i want previous question with earlier selected answer when i click to previous button.
Asp.net c# Thank you.
Either store and load Question and answer values in the session.
or have one page with a multiview and swich views when navigating between 'pages' this way the viewstate information will be preserved.
You can use asp.net wizard too...
Wizard Class
Wizard Web Server Control Overview
Walkthrough: Advanced Use of the ASP.NET Wizard Control

is their any option to move data from database in click event of button in asp.net c#

Hi
I am displaying one question & their 4 options per page.
For that i have one label for question & radiobuttonlist for their answers.There is next button. after clicking next button i want to display another record.
I have tried this with dataset with random function, but its not proper. values gets repeated. so i want first record to be display in pageload & after clicking next button next record should move till record exists.
I want to move one record to another after clicking next button.
how i can do this?
asp.net, c#
Thank you.
Use any of the data controls like gridview, repeater or datalist and keep the paging property on.

How to prevent reposting of data before refresh?

Suppose there is button on which there is event for adding the total sum(there is coloumn Amount in gridview) and posting the data in gridview i.e update of gridview. I want that when user click on button it will update the gridview i.e data will inserted in geridview but it will not add current numeric value to the total sum unless user refresh the page.
For this how to do? Please tell me.
You can use telerik's ASP.NET AJAX controls.
Visit here http://www.telerik.com/products/aspnet-ajax/grid.aspx

Resources