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

Custom Controls

BRawn
28
Hi,

I'm developing an app where I want to call user controls and load it onto my main form via selections from toolstrip items.
Do I have to make my application MDI and load every user control as a child in the parent container?

As I'm not too familiar with MDI, I don't really want to do it this way.
The other thing that I'm kinda struggling with is this:

I put my connection string to my database in my app.config file, then I wrote a class which has two methods, a string method to get the connection string out of the app.config and a method to create the connection to the SQL database.
Then, I have a logic class with a global variable which references the connection class and uses my createConnection() method. All this works great. On my form's code-behind file, I create a reference to my Logic class and initialize it as 'new' and I can call any method I've created in the logic class.

The problem I'm having now however, is that when I try to do exactly the same thing on a user control, my solution builds and the user control shows up in my toolbox as expected, but as soon as I try and drag it onto my main form I get a NullReferenceException which occurs in my connection class.
I don't understand this and need some help solving it as I've run out of ideas.
Jul 29 '11 #1

✓ answered by GaryTexmo

If you're connecting to a database as a part of your constructor and looking for compile time globals, I don't think you'll be able to do that. The global won't be initialized at design time.

You might try coding it so that if the control is in the designer, it doesn't try to connect to the database. The easiest way I know of is to access the DesignMode property on a control, but here's a thread discussing many other alternatives.

http://vidmar.net/weblog/archive/2005/04/11/1246.aspx

Give it a try. If your control isn't trying to access anything that's only available at runtime, you should be able to use it in the designer. Failing this, see where the NullReferenceException is thrown (I believe you can see the call stack from designer exceptions) and try to identify what might be causing it.

1 937
GaryTexmo
1,501 Expert 1GB
If you're connecting to a database as a part of your constructor and looking for compile time globals, I don't think you'll be able to do that. The global won't be initialized at design time.

You might try coding it so that if the control is in the designer, it doesn't try to connect to the database. The easiest way I know of is to access the DesignMode property on a control, but here's a thread discussing many other alternatives.

http://vidmar.net/weblog/archive/2005/04/11/1246.aspx

Give it a try. If your control isn't trying to access anything that's only available at runtime, you should be able to use it in the designer. Failing this, see where the NullReferenceException is thrown (I believe you can see the call stack from designer exceptions) and try to identify what might be causing it.
Jul 29 '11 #2

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

Similar topics

0
by: Jai | last post by:
Dear All Creating Custom Controls but Not User Controls,How to create custom controls,i.e Extending the functionality of the Existing Controls.(Web Custom Controls). Previously i have...
5
by: Dag | last post by:
Hi all, I have a project where we use lots of user controls. We would like to move them to private assemblied custom controls but from what I see this can't be done because the .ascx file must...
2
by: Crosta | last post by:
Hi everyone, As subject suggests I'm wondering how is it possible to do so in ASP.NET. The fact is that I'd like to "atomize" an entire series of custom user controls (.ascx and .ascx.vb) to...
3
by: David Freeman | last post by:
Hi There! I'm having trouble dynamically adding custom controls. My custom controls does not use code-behind but only <script /> block for programming. So as a result, I don't need to compile my...
6
by: Suzanne | last post by:
Hi all, 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...
2
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...
2
by: Laurent Bugnion | last post by:
Hi, I like to develop custom controls for a number of webpages. These controls are often customizable, so that they can be reused in a number of situations. My question is: What is the best...
0
by: Coolrah | last post by:
Hi to all, I am developing a Binder Manager which bind and unbind data from the webpage , i have almost completed the component with custom controls But i m facing one problem that i want to show...
3
by: Stephen.Schoenberger | last post by:
I have a windows form that has a panel on it. At runtime a custom control is added multiple times to this panel. (anywhere from 1-50 of them are added). I am trying to figure out how I can "select"...
1
by: Abdo Haji-Ali | last post by:
Previously I used to create user controls if I wanted to use a specific set of controls in multiple pages, however I want to deploy my control in other applications so I thought of creating custom...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.