Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 3rd, 2007, 02:51 PM
Friend of Wrox
 
Join Date: Sep 2007
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default Why am I getting this Server Error?

Hi

I am making a flash card sort of program for Japanese. They have 2 character sets Hiragana and Katakana. I got the Hiragana one to work but now I added the Katakana one and it screwing up my Hiragana. Like say they are on the Hiragana section and choose the characters they want and hit the next. It then goes to the katakana section so they can choose what they want but say they forgot one character they want in the Hiragana section so they hit the backbutton(that I have provided).


I get this error:



1 Server Error in '/Japanese' Application.
2 --------------------------------------------------------------------------------
3
4 An error has occurred because a control with id 'ctl00$ContentPlaceHolder1$ctl16' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error.
5 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
6
7 Exception Details: System.Web.HttpException: An error has occurred because a control with id 'ctl00$ContentPlaceHolder1$ctl16' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error.
8
9 Source Error:
10
11 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
12
13 Stack Trace:
14
15
16 [HttpException (0x80004005): An error has occurred because a control with id 'ctl00$ContentPlaceHolder1$ctl16' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error.]
17 System.Web.UI.Page.ProcessPostData(NameValueCollec tion postData, Boolean fBeforeLoad) +911
18 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3776
19
20
21

Before I added the new kataKana section I could go back without getting this error but it would not keep the results(it would clear all the boxes that where checked).

 Now the code.


Code:
1  /*Declares an arraylist that will store the checked checkboxes */
    protected ArrayList checkBoxStore = new ArrayList();
    protected ArrayList checkBoxStoreKata = new ArrayList();
    /* Declares an arraylist that will store the images of the checked items */
    protected ArrayList imageStore = new ArrayList();
    protected ArrayList imageStoreKata = new ArrayList();     

protected void makeHiragana()
2        {
3            SqlCommand comm;
4            SqlDataReader reader;
5            /* Grabs the stuff out of the database */
6            comm = new SqlCommand("SELECT HiraganaCharacter,HiraganaImage FROM Hiragana", getConnection());
7            /* opens the database */
8            comm.Connection.Open();
9            reader = comm.ExecuteReader();
10           try
11           {
12               /* reads through the database */
13               while (reader.Read())
14               {
15   
16                   /* make a new CheckBox */
17                   CheckBox newCheckBox = new CheckBox();
18   
19                   /* put the letter from the database into the ID of the checkbox */
20                   newCheckBox.ID = (string)reader["HiraganaCharacter"];
21   
22                   /* make a new image control */
23                   Image image = new Image();
24                   image.Width = 40;
25   
26   
27                   /* put the image url fromt he database into the image control */
28                   image.ImageUrl = (string)reader["HiraganaImage"];
29   
30                   /*add the check boxes to an arraylist */
31                   this.checkBoxStore.Add(newCheckBox);
32                   /* add the images to an arraylist*/
33                   imageStore.Add(image);
34               }
35   
36               makeTable();
37   
38           }
39           catch (SqlException ex)
40           {
41               Response.Write(ex.Message);
42           }
43           finally
44           {
45               /* closes the connections */
46               comm.Connection.Close();
47               reader.Close();
48           }
49       }
50   
51   protected void makeTable()
52       {
53           /*Makes the table to format the checkboxes and Images a bit better. */
54           int numcells = 5;
55           /* counts all the checkboxes and divides it by the cells then checks to see if a whole row is 
56            * made with mode if not a new row will be made */
57           int numrows = (checkBoxStore.Count / numcells) + (checkBoxStore.Count % numcells > 0 ? 1 : 0);
58           for (int j = 0; j < numrows; j++)
59           {
60               /* makes a new table row */
61               TableRow row = new TableRow();
62               /* makes the cells of the table */
63               for (int i = 0; i < numcells; i++)
64               {
65                   /* accounts for the last row where it would only have one in the whole row */
66                   int index = (j * numcells) + i;
67                   if (index >= checkBoxStore.Count)
68                   {
69                       break;
70                   }
71                   /* makes the table cell */
72                   TableCell c = new TableCell();
73                   /* takes the current image stored in the arraylist and sticks it in the control */
74                   Control img = (Control)imageStore[index];
75                   /* adds the control to the table cell */
76                   c.Controls.Add(img);
77                   /* takes the current checkbox stored in the arraylist and sticks it in the control */
78                   Control checkBox = (Control)checkBoxStore[index];
79                   /* adds the control to the table cell */
80                   c.Controls.Add(checkBox);
81                   /* adds the cells to the row */
82                   row.Cells.Add(c);
83               }
84                   Table1.Rows.Add(row);
85   
86    
87              
88           }
89       }
90   
91    protected void makeKatakana()
92       {
93           SqlCommand comm;
94           SqlDataReader reader;
95           /* Grabs the stuff out of the database */
96           comm = new SqlCommand("SELECT KatakanaCharacter,KatakanaImage FROM Katakana", getConnection());
97           /* opens the database */
98           comm.Connection.Open();
99           reader = comm.ExecuteReader();
100          try
101          {
102              /* reads through the database */
103              while (reader.Read())
104              {
105  
106                  /* make a new CheckBox */
107                  CheckBox newCheckBox = new CheckBox();
108  
109                  /* put the letter from the database into the ID of the checkbox */
110                  newCheckBox.ID = reader["KatakanaCharacter"].ToString();
111  
112                  /* make a new image control */
113                  Image image = new Image();
114                  image.Width = 40;
115  
116  
117                  /* put the image url fromt he database into the image control */
118                  image.ImageUrl = reader["KatakanaImage"].ToString();
119  
120                  /*add the check boxes to an arraylist */
121                  this.checkBoxStoreKata.Add(newCheckBox);
122                  /* add the images to an arraylist*/
123                  imageStoreKata.Add(image);
124              }
125              /*Makes the table to format the checkboxes and Images a bit better. */
126              int numcells = 5;
127              /* counts all the checkboxes and divides it by the cells then checks to see if a whole row is 
128               * made with mode if not a new row will be made */
129              int numrows = (checkBoxStoreKata.Count / numcells) + (checkBoxStoreKata.Count % numcells > 0 ? 1 : 0);
130              for (int j = 0; j < numrows; j++)
131              {
132                  /* makes a new table row */
133                  TableRow row = new TableRow();
134                  /* makes the cells of the table */
135                  for (int i = 0; i < numcells; i++)
136                  {
137                      /* accounts for the last row where it would only have one in the whole row */
138                      int index = (j * numcells) + i;
139                      if (index >= checkBoxStoreKata.Count)
140                      {
141                          break;
142                      }
143                      /* makes the table cell */
144                      TableCell c = new TableCell();
145                      /* takes the current image stored in the arraylist and sticks it in the control */
146                      Control img = (Control)imageStoreKata[index];
147                      /* adds the control to the table cell */
148                      c.Controls.Add(img);
149                      /* takes the current checkbox stored in the arraylist and sticks it in the control */
150                      Control checkBox = (Control)checkBoxStoreKata[index];
151                      /* adds the control to the table cell */
152                      c.Controls.Add(checkBox);
153                      /* adds the cells to the row */
154                      row.Cells.Add(c);
155                  }
156  
157                      Table2.Rows.Add(row);
158              
159  
160              }
161  
162  
163          }
164          catch (SqlException ex)
165          {
166              Response.Write(ex.Message);
167          }
168          finally
169          {
170              /* closes the connections */
171              comm.Connection.Close();
172              reader.Close();
173          }
174      }
Like I have its own table for the katakana and I even made different arrays to store the stuff but nothing seems to stop that error from coming(unless I remove the makeKatakana() and makeTableKata() then I can go back and won't get that error).

If needed I can post my file up so you guys can dl and maybe have a better time seeing it.



 
Old September 3rd, 2007, 02:56 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

since you are creating objects on the fly with data from a table, are you sure that the table has only unique values???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server Reg. SQL Server does not exist error Arsi SQL Server 2000 1 June 11th, 2008 11:20 AM
What is the error message for a 500 server error? chobo2 C# 2005 1 May 4th, 2008 03:11 AM
Error 500 -- Internal Server Error Vijay Kumar Servlets 2 March 26th, 2007 02:10 AM
server error when uploading to remote server ammweb ASP.NET 1.0 and 1.1 Basics 7 July 30th, 2006 01:51 AM
Error in Server when submitting this to the server zach2004 Classic ASP XML 0 March 8th, 2004 03:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.