473,395 Members | 1,941 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,395 software developers and data experts.

Postback problem

35
Hi guys,
I am taking a column from a table and comparing each row in that table with a similar column in a gridview row by row. For each identical answer, grade increments by 1. after all the rows have been iterated through, the final grade is placed in another table. This worked for a while till i inserted in cookie variables for the updating it now works on and off. have any ideas what could be causing that? sometimes it increments the grade and updates the table rightly and at other times on postback, it just reloads the page! could the cookie variables be causing a problem?
here's my code:
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.  
  4. TextBox1.Text = (string)Session["test_course"];
  5.  
  6.  
  7. }
  8. //Declaring the variables
  9.  
  10. string studentAnswer;
  11. string lecturerAnswer;
  12. int Grade;
  13. int i = 0;
  14. int j = 0;
  15.  
  16.  
  17. public void Button1_Click(object sender, EventArgs e)
  18. {
  19. //Code to retrieve data from Questions table 
  20. DataSet1TableAdapters.QuestionsTTableAdapter adapter = new DataSet1TableAdapters.QuestionsTTableAdapter();
  21. DataSet1.QuestionsTDataTable questions = adapter.GetData();
  22.  
  23.  
  24. //Code to retrieve data from test101 table
  25. DataSet1TableAdapters.test101TableAdapter testadapter = new DataSet1TableAdapters.test101TableAdapter();
  26. DataSet1.test101DataTable grading = testadapter.GetData();
  27.  
  28.  
  29. //looping through each row in gidview to retrieve student's answer to multiple choice questions
  30. foreach ( GridViewRow row in GridView1.Rows ) 
  31.  
  32. //looping through questions table via table adapter to retrieve the lecturer's answer
  33.  
  34.  
  35.  
  36. foreach(DataRow rowss in questions.Rows)
  37. {
  38. DataSet1.QuestionsTRow rowT = questions[i];
  39.  
  40. if (TextBox1.Text == rowT.coursecode)
  41. {
  42. lecturerAnswer = rowT.Answers;
  43. break;
  44. }
  45. else
  46. {
  47. i++;
  48. }
  49. }
  50. i++; 
  51.  
  52.  
  53. RadioButtonList radiolist = (RadioButtonList)row.FindControl("RadioButtonList1");
  54.  
  55. if (radiolist != null)
  56. {
  57. foreach (ListItem litem in radiolist.Items)
  58. {
  59. if (litem.Selected)
  60. {
  61. studentAnswer = radiolist.SelectedItem.Value.ToString();
  62. }
  63. }
  64. }
  65.  
  66. //Grading
  67. if (studentAnswer == lecturerAnswer)
  68. {
  69. Grade = Grade + 1;
  70. }
  71. else
  72. {
  73. Grade= Grade + 0;
  74. }
  75.  
  76. }
  77. //storing grade in session variable so that grade is not lost on post back
  78. Session["grade"] = Grade;
  79.  
  80. if (Session["grade"] == null)
  81. {
  82. Grade = 0;
  83. }
  84. else
  85. {
  86. Grade = (int)Session["grade"];
  87. }
  88.  
  89. //use of cookies to upgrade student's data. get student details, find particular row that matches and update that row.
  90. HttpCookie cookie = Request.Cookies["userdata"];
  91.  
  92. foreach(DataRow rows in grading.Rows)
  93. {
  94. DataSet1.test101Row rowG = grading[j];
  95.  
  96. if (rowG.Course_code == cookie["course"] && rowG.Registration == cookie["reg"] && rowG.Surname == cookie["surname"])
  97. {
  98. rowG.BeginEdit();
  99. rowG.Grade = Grade;
  100. rowG.EndEdit();
  101. testadapter.Update(grading);
  102. grading.AcceptChanges();
  103. Response.Redirect("Direction3.aspx");
  104.  
  105. }
  106. else { j++; }
  107.  
  108.  
  109. }
  110.  
  111.  
  112. }
  113.  
  114. thanks....
  115.  
Jan 10 '08 #1
1 1150
kenobewan
4,871 Expert 4TB
You may be able to control this using not page.ispostback in your code:
If Not Page.IsPostBack
Jan 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Igor Belagorudsky | last post by:
Hi, i am trying to analyze data submitted in a form but the problem is that when i try to create the controls in code (which is what i want to do), it throws an obect not found exception on...
0
by: Xavier Osa | last post by:
Hi, I have an ASP.Net web page that you can download a file. As Fergunson's problem, it prompts twice dialog boxes only if I select Open button. If I select Save button, it prompts once. I'm...
1
by: Mad Scientist Jr | last post by:
I don't know how this is happening, but a dropdown control I have is resetting to the 2nd value on the list anytime a postback occurs. I have no initiation code outside of If Not (IsPostBack) ...
10
by: Krista Lemieux | last post by:
I'm new to ASP.NET and I'm not use to the way things are handled with this technology. I've been told that when I have a control, I should only bind the data to it once, and not on each post back...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
6
by: | last post by:
Hi all, I have a bunch of dropdownlists that are populated in client-side javascript. When i do a postback I get the following error:- Invalid postback or callback argument. Event...
1
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
1
by: Jason | last post by:
I have a webpage that I've wrapped in an Atlas UpdatePanel. This page contains four textboxes, each with AutoPostBack set to true. The problem comes when someone edits the first box and tabs to...
11
by: antonyliu2002 | last post by:
I know that this has been asked and answered thousands of times. As a matter of fact, I know that I need to say If Not Page.IsPostBack Then 'Do something End If for things that needs to be...
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"...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.