Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Quick Error

  Asked By: Lisa    Date: Sep 14    Category: Asp.net    Views: 665
  

I have Made a declaration


Protected WithEvents StyleSheetURL As
System.Web.UI.HtmlControls.HtmlControl
and used in Body_load as
StyleSheetURL.Attributes.Add("href",
getStyleSheetPath()),

I have done it in all the pages
but in one of the Pages I am getting an Error

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

if I comment this Line and Go further It Gives me the
same error for a response.write too

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Iris Sanders     Answered On: Sep 14

Probably you have different IDs in ASPX file and codebehind file...
Misspelled... I do that often.

 
Answer #2    Answered By: Olga Allen     Answered On: Sep 14

I checked the Whole file and its too big a file can
you be specific where excatly I might have Given wrong
ID.

 
Answer #3    Answered By: Haboos Kauser     Answered On: Sep 14

Don't know but when adding stuff programmatically ( as I am doing at the moment also) I have found THAT error, the old Obj ref not set, popping up everywhere.

I tend to stick a lot of "new"'s everywhere.
I use c# so am not on the ball with VB sytax.
In C# I would use
System.Web.UI.HtmlControls.HtmlControl StyleSheetURL;
in the declaration and then instantiate as a 'new' in the initialise
StyleSheetURL = new System.Web.UI.HtmlControls.HtmlControl();

Then you have an object. Seems to clear a lot up.

Don't know what the VB syntax is though ??

If its only happening in one of the pages  then there's something wrong with that page specifically, surely. you've probs leant on the keyboard with that page open !

 
Answer #4    Answered By: Bama Cohen     Answered On: Sep 14

I think the thing is with your dynamic repeater creation. You have to make shure you recreate it in Page Load everytime the page postbacks. 'Till this event only controls that are in aspx are put into page control tree. Everytime that server sends data to client the whole page is disposed, so you have to recreate everything again.

You must create Item template by adding other controls to it. i.e.
repeater_object.ItemTemplate.Controls.Add(some_control)...
but don't forget to give them ID's.

In ItemDataBound event you can still do the FindControl... If the server gives other actual ID's try displaying all ID's of the item to see if your item resides inside ItemTemplate...

FindControl iteself won't raise exception, but casting and using refference may if FindControl returns null. Probably this is your problem.

 
Answer #5    Answered By: Hadil Khan     Answered On: Sep 14

First you have your Web control in the ASPX file (I hope you added it inside.
otherwise this is the cause...) and then declared in the codebehind (aspx.cs or
aspx.vb) as protected System.Web.UI.blah.blah...

If ID in ASPX file is the same as object  declaration name in the codebehind you
shouldn't get the exception. Unless you called Clear() of the container
containing your control.

Does this sound understandable?

 
Didn't find what you were looking for? Find more on Quick Error Or get search suggestion and latest updates.




Tagged: