calling method in user control - keep getting error - Object reference not set to an instance of an object.


If i dont call any methods of this user control The page runs fine and the user control displays correctly.

But I need to pass some data to my user control but every time i try to call one of the user control methods I get the error -

 Object reference not set to an instance of an object.


I cant figure it out as I've used user controls before - but this user control has a datagrid - I think this might be why it is erroring?

The html code look like - 


<%@ Register TagPrefix="Check" TagName="CheckGrid" src="../includes/UserControls/Permissions_Grid.ascx"%>

 <Check:CheckGrid id="Permissions" runat="Server"></Check:CheckGrid>


The code behind for the aspx that calls the user control is


Protected Grid As Permissions_Grid

Grid.Title = "24" 


The user control's class is called Permissions_Grid


If you need any more information  then please jsut ask and thanks for looking.



10/7/2006 11:52:53 PM 93655 articles. 3 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 39

If you use ASP.Net 1.x, make sure the User control that you will access is decalred at the top of the code with the other controls. Just delcare it with the same name as the id of the control and the typ (don't instanitate it, only do a declaration). That should probably solve the problem for you.

If you use ASP.Net 2.0, you can add the @reference directive to the page that points to the user control.

/Fredrik Normén - fredrikn @ twitter

Microsoft MVP, MCSD, MCAD, MCT

My Blog
10/8/2006 6:41:30 AM

Presuming you creating a dynamic instance -

The object is not instantiated -

Protected Grid As Permissions_Grid

Protected Grid As New Permissions_Grid




For the benefit of all users please mark any post answers as appropriate.
10/8/2006 7:05:56 AM

Actually after another quick look, you are using an ASPX coded instance. Access the instance by ID.

Permissions.Title - where title is a property on the control.


For the benefit of all users please mark any post answers as appropriate.
10/8/2006 7:07:32 AM

Similar Artilces:

Why is my ATLAS TEMPLATED USER CONTROL getting all instances of this controls methods called? I only want it called for the instance that I click the button from...
I have created a templated user control and it uses ATLAS. So...once the control loads, it then makes an ajax call to populate itself. "server" UpdateMode="Conditional" ID="UpdatePanel1" ChildrenAsTriggers="False" > "TNews1" runat="server"> BNNews(<%# Container.Row["TotalItems"].ToString()%>) <%# Container.Row["NewsID"] %> - "BNP35.aspx?newsId=<%# Container.Row["NewsID"]%>&promoId=<%# TN...

Can a web user control access other controls? (Currently getting null reference errors)
Hi. I'm working on several administration web pages. A lot of them require me to enter in a mailing address. I created a user control called address. In another user control named organization, I have three address controls. When an organization loads, if there's an existing address ID, I'm trying to call a public address function called, loadAddress. When I do, I get the following error: System.NullReferenceException: Object reference not set to an instance of an object. at sender, EventArgs e) in c:\document...

System.Null Reference Error When A user Control Is Called in the Web Page
Hi!!Some one is There who will  Give Some Solution!!!!I have a web application ,which is working well thru a URL.The same application is consumed via a framset on the Unix Server.It is working properly on the Unix , but sometimes it gives an  Error. The Error is: System.NullReferenceException: Object reference not set to an instance of an object. at Menu.Page_Load(Object sender, EventArgs e) in Menu.ascx.vb In my application, i m using a Web User Control (Menu.ascx). I declared some property in the User Control .I m using the user control in my aspx page at the PageLoad event of ...

Access a Web User Control Method from a Web Form
I'm trying to pass the Selected Index value from a web user control in a web form to the user controls selectedIndexchanged Sub.  I can't seem to figure out how to pass the information that I need to the user control and have it execute the sub routine. In the SelectedInedxChanged Sub I have a switch Statement and I want to get the index value from the web form where the user control is located and compare it to each case and then to have it execute the code for the case that it matches. What do I need to do? Hi, I am not sure if I understood your question correctly. I su...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

Getting the Selected Item of dropdownlist inside Web User Control on a Web Form
Ive got a dropdownlist control inside a web user control called Entity.ascx. This web user control is on a webform.aspx. In Entity.ascx class I created a SelectedEntity property that returns the selected item in the dropdownlist. Inside webform.aspx when btnGo is pushed I set a string and pass it in the url. I am trying to get the entity they selected via the property (SelectedEntity) inside Entity.ascx. As the SelectedEntity property tries to return the selected item in the dropdownlist I get this error: System.NullReferenceException: Object reference not set to an instance...

how to call controls of web control form in coding of other forms?
hello everyone i have one problem i have created one webcontrol shoppingcart in which there are two labels one of qty and other of amt which are initially enable =falsenow on other page(aspx page) i have one txtbox of qty as txtqty i want tat as soon as user enters qty txtqty and clicks on add cart button it shd be display d value in lblqty of web control shopping cart make sure i m using datalist on aspx page so give me suggestions on tat basis and my coding is in vb. plz give ur suggestions as fast as possible. Neeti what do you mean by webcontrol.... it this user control or normal ...

Getting Error :This method cannot be called until the send method has been called.
Hi, I am facing one tentative error when I am trying to call a page using "XMLHTTP" object. Error description is: This method cannot be called until the send method has been called. Following is the code snippet: Set objHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0") Call objHTTP.Open("GET", GetHTTP, False) Most of the time, above code is working properly, but some time (I don’t know why) above error occurred. Can any one help me in this regard? Thank you.~ Firoz AnsariPune, Indiahttp://www.firozansari.comWhy product testin...

call method of parent user control on child user control
Hi, Does any1 let know , How to call method of parent user control on child user control actually my parent user control has a button .... and i wnt to call button click event of parent user control at child user control . Its Urgent plzz. Thanks, Mohit  In your parent UserControl, expose a public method.  Then in the child user control, cast Parent as the parent UserControl's type and call the method. (Parent as ParentUserControlType).MyPublicMethod();  "You shall love the LORD your God with all your heart and with all your soul and with all your mig...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

Calling Web form from User Control
Hi I want to retirve the webform controls data using User control which is placed in the same web form. Thanx in advance Narendra Welcome to the ASP.NET forums, Narendra. You should get the Page to do the work of passing a value to the User Control. A User Control should not really be poking about in its containing Page. If you tell me which language you use (C# or VB.NET), I'll write an example.Alister Thanx a lot for u r reply. I'm using VB.NET,if possible u can give an example in C# also. Thanx in advance Here is the user control. You will see that I h...

Calling a user control method from another user control code behind
Hi there,In a webform I have a FormView. The ItemTemplate contains two users control, UC1 and UC2.  When certain event fires in UC1´s code behind, I need to call a public method in UC2. So I think from UC1´s event code I need to find the container FormView first, then find the ItemTemplate and finally find UC2 inside it, and then call UC2´s method.Is that the way to go? I would appreciate a lot some ideas/suggestions/C# examples on how to do this.Thanks in advance.    You can create a public method in a separate class so that you can call that method anywhere in your codes.....

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

calling user control (.ascx) in web form?
Hi, I have a user control file which is displaying a data grid, the code including "Sub Page_Laod()" ... Originally, this part is in my .aspx page ... now I seperate it in a user control file, and use <%@ Register TagPrefix="dg" TagName="dgCC" Src="\ss1\control\dg.ascx" %> to call the user control file in my .aspx page. I have 2 questions ... 1) which one is faster? Using user control or includes the data grid part in my .aspx page directly? I create a user control coz' other pages might need to use the same data grid. 2) In my user control page,...

Why Page_Load of my web user control is not get called?
I have a web user control and I want to set a property during its initializaiton. But the page_lode method of the control is not get called when I debug it. Here is my control code: private int myId = 1; private void Page_Load(object sender, System.EventArgs e) { if (myId == 1) { btnTitle.Text = "First button"; } if (myID == 2) { btnTitle.Text = "Second button"; } } Don't know why. Did I miss anything here? Thanks. Look for the InitializeComponent method. (I...

Web resources about - calling method in user control - keep getting error - Object reference not set to an instance of an object. -

European Terrestrial Reference System 1989 - Wikipedia, the free encyclopedia
The European Terrestrial Reference System 1989 ( ETRS89 ) is a ECEF (Earth-Centered, Earth-Fixed) geodetic Cartesian reference frame , in which ...

Child sex abuse royal commission: Senior politician to be grilled over reference
A former deputy Premier will again take the stand on Tuesday to explain why he gave a positive job reference to a man he knew to have sexually ...

How many Nazi references in the Republican race is enough? Top Stories
Check out Neil Macdonald's take on the two main contenders in the wild race for the Republican nomination. And, Canada Post's plans for the community ...

VA, reference pricing and the value of options
@hyperplanes eg, you can get free care at VA, or get a reimbursed at the reference price for care anywhere else. — Matthew Martin (@hyperplanes) ...

10 of the best movie references you’ll ever see in popular TV shows
I'm torn when it comes to breaking the fourth wall in TV shows . It can be a fun, clever way to connect with the audience, but it can also break ...

"As much as Poppy Bush scoffs at 'the D-word,' as he calls any reference to dynasty, the Bushes do consider ...
... re-defended myself: "Servants" seems like the right word for people who occupy the servants' quarters within a house, especially when the reference ...

Donald Trump prompts Nazi references
Some conservatives and political commentators say the GOP frontrunner's rhetoric has crossed the line

Arrow: Easter Eggs and DC Comics References in "Brotherhood"
This was a weird week for Arrow, in terms of the crazy minutia we generally look for.There were a [...]

The 5 Best Britney Spears References From Her 'Jane the Virgin' Visit
The 5 Best Britney Spears References From Her 'Jane the Virgin' Visit

Virginia Mayor References Japanese Interment to Make Point About Syrian Refugees
Today, Roanoke, Va., mayor David Bowers acknowledged similarities between banning assistance to Syrian refugees based on their country of origin ...

Resources last updated: 11/30/2015 6:33:30 AM