473,789 Members | 2,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Custom Event Question

3 New Member
Hi I am writing a custom tab control. I am capturing a caption property in a page which then changes the caption of the associated tab. (Similar to window's tab control).

I am using a delegate to capture the event of the change of the property and then I am changing the text value of the associated tab. The problem is that after I added the delegate code, I am unable to render the form in the designer. It's telling me that the 'Object reference not set to an instance of an object.'

The error is traced back to the InitializeCompo nent() where the user control attempts to set the default value on the caption property.

Here is the code snippets.

Error happens here:
Expand|Select|Wrap|Line Numbers
  1. this.tabPanelPageContainer1.Caption = "";
Property code:
Expand|Select|Wrap|Line Numbers
  1. public string Caption
  2.         {
  3.             get
  4.             {
  5.                 return _caption;
  6.             }
  7.             set
  8.             {
  9.                 _caption = value;
  10.                 OnCaptionChange(new PageEventArgs(_caption));
  11.             }
  12.         }
  13.  
Delegate Class
Expand|Select|Wrap|Line Numbers
  1. /// <summary>
  2.     /// Event arguments class for the page events
  3.     /// </summary>
  4.     public class PageEventArgs : EventArgs
  5.     {
  6.         private string _caption;
  7.  
  8.         public PageEventArgs(string caption)
  9.         {
  10.             _caption = caption;
  11.         }
  12.  
  13.         public string CaptionValue
  14.         {
  15.             get
  16.             {
  17.                 return _caption;
  18.             }
  19.         }
  20.     }
  21.  
Any idea why it's doing this?
Sep 17 '08 #1
2 1237
balabaster
797 Recognized Expert Contributor
I would hazard a guess that it's trying to assign a value to an object that technically doesn't exist yet. For instance - when you try and set the value in the initialize, it will fail because the object doesn't exist until the initialize phase is completed. Usually you would do stuff like this in the PreRender phase where you know the object exists...
Sep 17 '08 #2
deviantseev
3 New Member
I would hazard a guess that it's trying to assign a value to an object that technically doesn't exist yet. For instance - when you try and set the value in the initialize, it will fail because the object doesn't exist until the initialize phase is completed. Usually you would do stuff like this in the PreRender phase where you know the object exists...
Yeah, I am trying to get to the bottom of why the object is not being initialized but when I attach visual studio to the debugger and launch, it does not seem to be hitting the breakpoint set within the parent's InitializeCompo nent(). Any ideas on how else I can debug this issue?
Sep 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

21
2105
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a string with comma delimited values. For example, if I were to render two text boxes. One with the Value Terry and the Other with the Value 'Burns' I would get the following value Terry,Burns.
5
4547
by: | last post by:
I am wondering what the best method of attaching custom Events to custom WebUserControls are. I cannot seem to find the proper terminology to expand my research. Basicallly I have a custom user control that has 2 or 3 events selectionChanged DropDownOpened I would like the user to be able to attach Server Side events for both. I have the client side implementation worked out. I just need to find a proper way to to get everything...
3
1869
by: Chris Newby | last post by:
I have a very simple custom control that derives from WebControls.Panel and implements INamingContainer. It appear that controls created as children of my custom control are having ViewState problems. For example, suppose I create a ListBox control as a child of my custom control, attach a SelectedIndexChanged event handler to it, and bind its data in the Page_Load event handler only if the current request is not a post back. I load the...
7
3346
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid, theres a requirement to show a drop down menu list (this is a control I downloaded online) in one of the columns. For the purposes of this question, Ive implemented the drop down menu as a drop down list instead. Ive got all this working at this...
2
2597
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a good while and I'm getting really frustrated now! My problem is this - my custom controls periodically disappear from my
4
1127
by: Jon Paal | last post by:
I have a custom server control which renders some html. I want to capture some interim values generated by the control as it processes the data. is there a way to capture and retrieve the interim values generated by the control, so they can be used elsewhere in the display page ?
0
1666
by: Walter | last post by:
Hi, can someone please help me with my custom control viewstate problem....I haven't slept for hours trying to get this fixed. I am making two custom controls which will be included on a single page. For now, I will call them box1 and box2. Each box has a panel and will display a list of link buttons on the panel. When the page loads for the first time, box1 will call the database and create a list of linkbuttons and each link button has...
15
6523
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt accept other controls. The control i drag drop on it becomes the child of my custom control's parent form and not the child of my custom control. Then i added this line "" before my custom control class (i dont know what this line does). Now
0
2132
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Actually, my installer package is not for a Windows Service, but for a WinForms application. Well, it is kind of both: this is a multi-project solution with its main target being a WinForms application, but it also includes a Windows Service. My custom install actions configuration includes output from a Class Library project that contains the custom actions followed by the output of the Windows Service project to register the service....
4
2493
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried unsuccessfully in creating the whole pane as a user control and have succeeded in adding the pane and then dynamically adding the content which is a user control to the pane, dynamically within the page. However I would like to have a single pane...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10410
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10139
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.