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

ASP .NET Web Controls

I'm having trouble working with web controls from the C# code behind file
Some controls are accessible to me programatically, and some are not

For example, I trying to hide, or display an <asp:Table> on post back o
the page, here is my code

HTM

<asp:Table id="commentTable
runat="Server"><asp:TableRow><asp:TableCell>Som
Text</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

commentTable.Visible = isPostBack
I get this error anytime I run the app

Object reference not set to an instance of an object
Description: An unhandled exception occurred during the execution of th
current web request. Please review the stack trace for more informatio
about the error and where it originated in the code

Exception Details: System.NullReferenceException: Object reference not se
to an instance of an object

Source Error

Line 37: commentTable.Visible = isPostBack

If you have experienced a similiar problem, please help.
Nov 18 '05 #1
12 1365
Also, I want to mention that this only seems to be happening when I embed the table in a repeater in the <ItemTemplate></ItemTemplate

Thanks.
Nov 18 '05 #2
you should access the table thru Repeater. rather than accessing the table,
you can set Repeater.visible property if only the table exists in the
repeater.

Av.
"codeWarrior" <an*******@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
Also, I want to mention that this only seems to be happening when I embed
the table in a repeater in the <ItemTemplate></ItemTemplate>

Thanks.

Nov 18 '05 #3
Thanks for the response, however

1.) I want to hide/display more than just the repeater (surrounding controls)
2.) This error still occurs on the repeater itself (which by the way is nested in another repeater)

I think this error is occuring because the nested table isn't created yet for some reason. Like I said, if it isn't in the repeater, it works fine

I thought the load event fired after everything was created?
Nov 18 '05 #4
when you include tables inside the repeater control, you will not see this
code..
protected System.Web.UI.WebControls.Table commentTable;

it will only appear only if you add the table using drag/drop in design
mode. i think you have created one table in code behind with same name as
that in the repeater control and you are accessing the other one (not the
table in repeater control). can you paste your complete code..

Av.

"codeWarrior" <an*******@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
Thanks for the response, however,

1.) I want to hide/display more than just the repeater (surrounding
controls).
2.) This error still occurs on the repeater itself (which by the way is
nested in another repeater).

I think this error is occuring because the nested table isn't created yet
for some reason. Like I said, if it isn't in the repeater, it works fine.

I thought the load event fired after everything was created?

Nov 18 '05 #5
I think you are correct. I didn't want to use the designer to layout the page, so I manually coded the layout with HTML. I added the table to the HTML source, and then declared it in the code behind. So, rather than posting my code wich basically illustrates this, allow me to ask a question

If I don't want to use the designer, how do I get the code behind to look at the HTML element

If you still want to see the all the code, I will post it. Oh, and thanks so much for your assistance. I searched, and searched on this to no avail.
Nov 18 '05 #6
to set the visible property of the asp:table control, you should access it.
but i am not sure when you want to set the visible property.

when repeater control is bound to a datasource, it creates an asp:table for
each row in the source..right.. so you will see so many tables. if you want
to set visible property of table in a row, you should do it in any of the
events of repeater like

Repeater1_ItemCreated or Repeater1_ItemCommand.
e.Item.FindControl("tablename") returns the table object in that row.

hth,
if you can clearly state when you want to set visible property, i can focus
on it.

Av.

"codeWarrior" <an*******@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
I think you are correct. I didn't want to use the designer to layout the
page, so I manually coded the layout with HTML. I added the table to the
HTML source, and then declared it in the code behind. So, rather than
posting my code wich basically illustrates this, allow me to ask a
question:

If I don't want to use the designer, how do I get the code behind to look
at the HTML element?

If you still want to see the all the code, I will post it. Oh, and thanks
so much for your assistance. I searched, and searched on this to no avail.

Nov 18 '05 #7
If I do it on the Repeater1_ItemCommand, will it then output the HTML? I've tried this, and because it's initially invisible, the HTML isn't rendered. In other words, when I set the visible property to true, it still doesn't show up

private void repeaterNameHere_ItemCommand(object sender, RepeaterCommandEventArgs e

System.Web.UI.Control ctl = e.Item.FindControl("commentTablel").Visible = true
I know it gets in here, due to the break point I inserted. Also the ctl is set to the correct control when examined in the Autos pane

Nov 18 '05 #8
on which item command it comes up here? on click of something right? what is
it?. when on ItemCreated is it set to false?
the html will be rendered anyway irrespective of the visible property, only
thing is when to set it true is question?

Av.

"codeWarrior" <an*******@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
If I do it on the Repeater1_ItemCommand, will it then output the HTML?
I've tried this, and because it's initially invisible, the HTML isn't
rendered. In other words, when I set the visible property to true, it
still doesn't show up.

private void repeaterNameHere_ItemCommand(object sender,
RepeaterCommandEventArgs e)
{
System.Web.UI.Control ctl = e.Item.FindControl("commentTablel").Visible =
true;
}

I know it gets in here, due to the break point I inserted. Also the ctl is
set to the correct control when examined in the Autos pane.

Nov 18 '05 #9
Oops, messed that code up a little when typing here's what I meant

private void repeaterNameHere_ItemCommand(object sender, RepeaterCommandEventArgs e

e.Item.FindControl("commentTablel").Visible = true
}
Nov 18 '05 #10
On ItemCreated it is set to false

On the ItemCreated event of a repeater is when the event fires and the sub control is set to true

repeaterNameHere.ItemCommand += new RepeaterCommandEventHandler(repeaterNameHere_ItemC ommand)

private void repeaterNameHere_ItemCommand(object sender, RepeaterCommandEventArgs e

e.Item.FindControl("tableNameHere").Visible = true
Nov 18 '05 #11
hey this is what is tried and it works for me..

repeater control html :
<asp:repeater id="Repeater1" runat="server">
<ItemTemplate>
<asp:Button ID="button1" CommandName="select" Visible="True"
Runat="server" Text="set"></asp:Button>
<asp:Table ID="Table1" Runat="server" Visible="true">
<asp:TableRow>
<asp:TableCell>one</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
</asp:repeater>

ItemCreated : e.Item.FindControl("Table1").Visible = false;
ItemCommand : e.Item.FindControl("Table1").Visible = true;

Page_Load :

if(!IsPostBack)
{
object[] arr = new object[] {"one","two","three"};
Repeater1.DataSource = arr;
Repeater1.DataBind();
}

it is setting the visible property to true. check if you have IsPostBack and
you are not binding DataSource everytime.

hth,
Av.

"codeWarrior" <an*******@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com...
On ItemCreated it is set to false.

On the ItemCreated event of a repeater is when the event fires and the sub
control is set to true:

repeaterNameHere.ItemCommand += new
RepeaterCommandEventHandler(repeaterNameHere_ItemC ommand);

private void repeaterNameHere_ItemCommand(object sender,
RepeaterCommandEventArgs e)
{
e.Item.FindControl("tableNameHere").Visible = true;
}

Nov 18 '05 #12
It does help. You the man! Thanks for everything.
Nov 18 '05 #13

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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.