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

ASP .NET Web Controls

Hi

I'm having trouble accessing controls in an ASP code behind file. Here is an example

HTML

<asp:Table id="commentTable" runat="server" Visible="False"><asp:TableRow><asp:TableCell><asp: Repeater Runat="server" ID="comments" DataSource='<%#DisplayComments(DataBinder.Eval(Con tainer.DataItem, "ID")) %>'><ItemTemplate><%# DataBinder.Eval(Container.DataItem, "CommentBody") %></ItemTemplate></asp:Repeater></asp:TableCell></asp:TableRow></asp:Table

C# code behin

protected System.Web.UI.WebControls.Table commentTable

private void Page_Load(object sender, System.EventArgs e

if (!IsPostBack

commentTable.Visible = false;


When the page loads for the first time, and enters the above condition, I always get this error

System.NullReferenceException: Object reference not set to an instance of an objec

However the commentTable is decalared at the top of the codeBehind, and maps to the HTML element with the same ID

If you've expierience a simialar problem, please relay your solutions. Thanks in advance.
Jul 19 '05 #1
1 1665
http://www.aspfaq.com/5002

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"codeWarrior" <an*******@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
Hi,

I'm having trouble accessing controls in an ASP code behind file. Here is
an example:

HTML:

<asp:Table id="commentTable" runat="server"
Visible="False"><asp:TableRow><asp:TableCell><asp: Repeater Runat="server"
ID="comments"
DataSource='<%#DisplayComments(DataBinder.Eval(Con tainer.DataItem, "ID"))
%>'><ItemTemplate><%# DataBinder.Eval(Container.DataItem, "CommentBody")
%></ItemTemplate></asp:Repeater></asp:TableCell></asp:TableRow></asp:Table>

C# code behind

protected System.Web.UI.WebControls.Table commentTable;

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
commentTable.Visible = false;
}

}

When the page loads for the first time, and enters the above condition, I
always get this error:

System.NullReferenceException: Object reference not set to an instance of
an object

However the commentTable is decalared at the top of the codeBehind, and
maps to the HTML element with the same ID.

If you've expierience a simialar problem, please relay your solutions.
Thanks in advance.

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
0
by: Mark Johnson | last post by:
Sometimes Controls that have been added to a GroupBox do not show up. What I am doing : 1) I am not using the designer, but create all the Controls per hand: groupBoxProdukt_01 = new...
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
1
by: Robert Howells | last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad architecture. I'd appreciate some feedback on the the wisdom (or lack thereof) in attempting the following: I'm not new...
10
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
6
by: dhnriverside | last post by:
Hi peeps, I'm trying to create some controls textboxes at runtime, based on the number of items in a IETreeView that are checked. That I can do, I've got a place holder and I can create the...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
7
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
8
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.