Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .NET Web Controls

Reply
Thread Tools

ASP .NET Web Controls

 
 
=?Utf-8?B?Y29kZVdhcnJpb3I=?=
Guest
Posts: n/a
 
      05-14-2004
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.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Y29kZVdhcnJpb3I=?=
Guest
Posts: n/a
 
      05-14-2004
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.
 
Reply With Quote
 
 
 
 
avnrao
Guest
Posts: n/a
 
      05-14-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.



 
Reply With Quote
 
=?Utf-8?B?Y29kZVdhcnJpb3I=?=
Guest
Posts: n/a
 
      05-14-2004
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?
 
Reply With Quote
 
avnrao
Guest
Posts: n/a
 
      05-14-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?



 
Reply With Quote
 
=?Utf-8?B?Y29kZVdhcnJpb3I=?=
Guest
Posts: n/a
 
      05-14-2004
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.
 
Reply With Quote
 
avnrao
Guest
Posts: n/a
 
      05-14-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.



 
Reply With Quote
 
=?Utf-8?B?Y29kZVdhcnJpb3I=?=
Guest
Posts: n/a
 
      05-14-2004
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

 
Reply With Quote
 
=?Utf-8?B?Y29kZVdhcnJpb3I=?=
Guest
Posts: n/a
 
      05-14-2004
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
}
 
Reply With Quote
 
avnrao
Guest
Posts: n/a
 
      05-14-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Web.config's <system.web><pages><controls><add /></controls></pages></system.web> To Register UserControls Nathan Sokalski ASP .Net 5 01-10-2007 10:50 AM
Using Web.config's <system.web><pages><controls><add /></controls></pages></system.web> To Register UserControls Nathan Sokalski ASP .Net Web Controls 4 12-21-2006 02:50 AM
Using Web.config's <system.web><pages><controls><add /></controls></pages></system.web> To Register UserControls Nathan Sokalski ASP .Net Building Controls 4 12-21-2006 02:50 AM
Issues in ASP.NET 2.0 when dynamically loading user controls or asp.net web controls??? Bob Rock ASP .Net 1 09-17-2006 01:49 PM
IntelliSense on Web User Controls and Web Custom Controls Axel Dahmen ASP .Net 1 11-12-2003 06:12 AM



Advertisments