473,385 Members | 1,542 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,385 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 1663
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.