Click here to Skip to main content
15,886,030 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
How is it posible for controls to be not found in the code behind the page? All the names are the same. Any clue?
Posted
Comments
Sandeep Mewara 16-Oct-10 5:04am    
What? Care to elaborate?
Anele Ngqandu 16-Oct-10 5:08am    
Am populating a combobox using a class, Now the weird thing the name of the combobox cannot be found in the code behind and every thing was working fine till now.
michaelschmitt 16-Oct-10 7:45am    
By "name", you mean "Id"? If not..there you go..And do you - maybe - care to post a snippet of your source-code?

And also, you can only "find" controls in code-behind by typing their "name/id", if the control is running on server side and therefor has a "runat=server" attribute.
Anele Ngqandu 16-Oct-10 8:10am    
Yes Sir by "name" I mean "ID"
//A method in code behind
public void populateCombo()
{
DataCls dtClass = new DataCls();

cboCourses.DataSource = dtClass.CognosComboBox();
cboCourses.DataBind();

}

// Below is My form

<asp:Content ID="Content1" ContentPlaceHolderID="sideContent" Runat="Server">
 <div class="entry">
<p>Register <a href="Register.aspx">HERE</a> if you not a member.</p>

<table border="0">
<tr>
<td> Choose course:</td>
<td>
<asp:DropDownList ID="cboCourses" runat="server">
</asp:DropDownList>
</td>

</tr>
<tr>
<tr><td colspan="2" align="center">
<asp:Button ID="btnEnroll" runat="server"
Text="submit" onclick="btnEnroll_Click" /></td></tr>


</table>

</div>
</asp:Content>

//Below is the code in my method

public ArrayList CognosComboBox()
{
dbConnection();

string sqlCBO = "SELECT courseName FROM Courses;";
dbCmd = new OleDbCommand(sqlCBO, dbConn);

OleDbDataReader reader = dbCmd.ExecuteReader();

ArrayList myList = new ArrayList();
myList.Add("Choose course");
while (reader.Read())
{
myList.Add(reader[0].ToString());
}
reader.Close();


dbConn.Close();

return myList;

}
Anele Ngqandu 16-Oct-10 8:11am    
Sorry Arry List Methos runs in my class

1 solution

copy and paste all the code behind and the code in the source view into a backup document, like word or notepad.
delete the page, and re-add it
then copy/paste your code back into source and the codebehind.

this happened me before, the link between the 2 files messes up. make sure you dont delete the first line of the source code in the .aspx file.
 
Share this answer
 
Comments
Dalek Dave 18-Oct-10 5:10am    
Good Call.
[no name] 18-Oct-10 5:29am    
:) thx dave

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900