473,387 Members | 3,821 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,387 software developers and data experts.

Testing existance of a control on the page

Hi all,
I have a usercontrol (a textbox with dropdown calendar that fills the
textbox with the selected date) that I implement in a datagrid in a webform.
On first loading the page, the datagrid's visibility is set to 'false', and
so the UC depCal is not rendered on the page. Hence the following code in
the InitializeComponent() method causes an error:
this.depCal.DateChanged += new
custCalendar.DateChangedEventHandler(this.depCal_D ateSet);

The error is: 'Object reference not set to an instance of an object'

Hence I think what I need to do is check for the existance of the control
depCal on the page before exectuing the above code snippet. I tried the
code below, again in the InitializeComponent() method, but it didn't work.
Even when the Datagrid and hence the control depCal is visible on the page,
I never get inside the IF statement.

if ( depCal != null ) {
this.depCal.DateChanged += new
custCalendar.DateChangedEventHandler(this.depCal_D ateSet);
}

Can you tell me if I'm approaching the problem from the right angle, and how
to solve it? Thanks in advance for your help,

Iain
Nov 18 '05 #1
4 1332
With .visibility = false, you should not throw an error. If you are
dynamically placing the control, it is another story. In that case, you can
add the event handler at the time you create the control on the page.

One way to toggle on and off is to place panels on the page and make the
whole panel invisible. It works very nice, esp. if you have multiple
controls that have to be toggled.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Iain Porter" <st***@intraspin.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Hi all,
I have a usercontrol (a textbox with dropdown calendar that fills the
textbox with the selected date) that I implement in a datagrid in a webform. On first loading the page, the datagrid's visibility is set to 'false', and so the UC depCal is not rendered on the page. Hence the following code in
the InitializeComponent() method causes an error:
this.depCal.DateChanged += new
custCalendar.DateChangedEventHandler(this.depCal_D ateSet);

The error is: 'Object reference not set to an instance of an object'

Hence I think what I need to do is check for the existance of the control
depCal on the page before exectuing the above code snippet. I tried the
code below, again in the InitializeComponent() method, but it didn't work.
Even when the Datagrid and hence the control depCal is visible on the page, I never get inside the IF statement.

if ( depCal != null ) {
this.depCal.DateChanged += new
custCalendar.DateChangedEventHandler(this.depCal_D ateSet);
}

Can you tell me if I'm approaching the problem from the right angle, and how to solve it? Thanks in advance for your help,

Iain

Nov 18 '05 #2
Is the problem that in the method InitialiseComponent(), we don't know
anything about the controls on the page, and hence can't tell if they exist
or not, or if they are visible or not?

Thanks - I will change them to panels, as there will be several controls
relating to the grid that will all become visible at once. I'm not
dynamically placing the controls - they are coded into the .aspx file - i
just toggle visibility.

Thanks, Iain

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:Oq**************@TK2MSFTNGP12.phx.gbl...
With .visibility = false, you should not throw an error. If you are
dynamically placing the control, it is another story. In that case, you can add the event handler at the time you create the control on the page.

One way to toggle on and off is to place panels on the page and make the
whole panel invisible. It works very nice, esp. if you have multiple
controls that have to be toggled.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Iain Porter" <st***@intraspin.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Hi all,
I have a usercontrol (a textbox with dropdown calendar that fills the
textbox with the selected date) that I implement in a datagrid in a

webform.
On first loading the page, the datagrid's visibility is set to 'false',

and
so the UC depCal is not rendered on the page. Hence the following code in the InitializeComponent() method causes an error:
this.depCal.DateChanged += new
custCalendar.DateChangedEventHandler(this.depCal_D ateSet);

The error is: 'Object reference not set to an instance of an object'

Hence I think what I need to do is check for the existance of the control depCal on the page before exectuing the above code snippet. I tried the
code below, again in the InitializeComponent() method, but it didn't work. Even when the Datagrid and hence the control depCal is visible on the

page,
I never get inside the IF statement.

if ( depCal != null ) {
this.depCal.DateChanged += new
custCalendar.DateChangedEventHandler(this.depCal_D ateSet);
}

Can you tell me if I'm approaching the problem from the right angle, and

how
to solve it? Thanks in advance for your help,

Iain


Nov 18 '05 #3
It is possible that the InitializeComponent event is a problem. In general,
I use Page_Load for common stuff and event handlers for control driven
events. I still like panels, as you make visible (or visa versa) in one
step, which is very convenient. The page weight is rather light, so it is
not a big maintainability versus performance issue.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Iain Porter" <st***@intraspin.com> wrote in message
news:ud******************@TK2MSFTNGP12.phx.gbl...
Is the problem that in the method InitialiseComponent(), we don't know
anything about the controls on the page, and hence can't tell if they exist or not, or if they are visible or not?

Thanks - I will change them to panels, as there will be several controls
relating to the grid that will all become visible at once. I'm not
dynamically placing the controls - they are coded into the .aspx file - i
just toggle visibility.

Thanks, Iain

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:Oq**************@TK2MSFTNGP12.phx.gbl...
With .visibility = false, you should not throw an error. If you are
dynamically placing the control, it is another story. In that case, you can
add the event handler at the time you create the control on the page.

One way to toggle on and off is to place panels on the page and make the
whole panel invisible. It works very nice, esp. if you have multiple
controls that have to be toggled.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Iain Porter" <st***@intraspin.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Hi all,
I have a usercontrol (a textbox with dropdown calendar that fills the
textbox with the selected date) that I implement in a datagrid in a

webform.
On first loading the page, the datagrid's visibility is set to 'false',
and
so the UC depCal is not rendered on the page. Hence the following
code in the InitializeComponent() method causes an error:
this.depCal.DateChanged += new
custCalendar.DateChangedEventHandler(this.depCal_D ateSet);

The error is: 'Object reference not set to an instance of an object'

Hence I think what I need to do is check for the existance of the control depCal on the page before exectuing the above code snippet. I tried
the code below, again in the InitializeComponent() method, but it didn't work. Even when the Datagrid and hence the control depCal is visible on the

page,
I never get inside the IF statement.

if ( depCal != null ) {
this.depCal.DateChanged += new
custCalendar.DateChangedEventHandler(this.depCal_D ateSet);
}

Can you tell me if I'm approaching the problem from the right angle,

and how
to solve it? Thanks in advance for your help,

Iain



Nov 18 '05 #4
So is the problem in the 'how' I'm testing for the existance of the control,
or the 'when'? Is Page_Load too early? I alse tried putting the code into
a Grid_Load event, but with the same results - the control always registers
as null.

Is there a later method in which I can test for the existance, i.e. a
once_the_control_has_loaded_to_the_page event?
How would I implement an onrender event?

Thanks again for your help,
Iain
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:u2**************@TK2MSFTNGP11.phx.gbl...
It is possible that the InitializeComponent event is a problem. In general, I use Page_Load for common stuff and event handlers for control driven
events. I still like panels, as you make visible (or visa versa) in one
step, which is very convenient. The page weight is rather light, so it is
not a big maintainability versus performance issue.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Iain Porter" <st***@intraspin.com> wrote in message
news:ud******************@TK2MSFTNGP12.phx.gbl...
Is the problem that in the method InitialiseComponent(), we don't know
anything about the controls on the page, and hence can't tell if they

exist
or not, or if they are visible or not?

Thanks - I will change them to panels, as there will be several controls
relating to the grid that will all become visible at once. I'm not
dynamically placing the controls - they are coded into the .aspx file - i
just toggle visibility.

Thanks, Iain

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in message news:Oq**************@TK2MSFTNGP12.phx.gbl...
With .visibility = false, you should not throw an error. If you are
dynamically placing the control, it is another story. In that case, you
can
add the event handler at the time you create the control on the page.

One way to toggle on and off is to place panels on the page and make

the whole panel invisible. It works very nice, esp. if you have multiple
controls that have to be toggled.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Iain Porter" <st***@intraspin.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
> Hi all,
> I have a usercontrol (a textbox with dropdown calendar that fills the > textbox with the selected date) that I implement in a datagrid in a
webform.
> On first loading the page, the datagrid's visibility is set to

'false', and
> so the UC depCal is not rendered on the page. Hence the following code
in
> the InitializeComponent() method causes an error:
> this.depCal.DateChanged += new
> custCalendar.DateChangedEventHandler(this.depCal_D ateSet);
>
> The error is: 'Object reference not set to an instance of an object'
>
> Hence I think what I need to do is check for the existance of the

control
> depCal on the page before exectuing the above code snippet. I tried

the > code below, again in the InitializeComponent() method, but it didn't

work.
> Even when the Datagrid and hence the control depCal is visible on the page,
> I never get inside the IF statement.
>
> if ( depCal != null ) {
> this.depCal.DateChanged += new
> custCalendar.DateChangedEventHandler(this.depCal_D ateSet);
> }
>
> Can you tell me if I'm approaching the problem from the right angle, and how
> to solve it? Thanks in advance for your help,
>
> Iain
>
>



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Lance | last post by:
Hi, How do you test for an object existing in C#? C# seems to differentiate between 'null' and non-existance. In other languages I could test as so: if(ex.InnerException.StackTrace != null)...
2
by: Lloyd Sheen | last post by:
Ok I have created a small testbed site for testing and I am have a problem with the terms Usercontrol, Webcontrol, etc. What I need to do in the long run is have a page using AJAX and having...
18
by: Andrew Wan | last post by:
I have been developing web applications with ASP & Javascript for a long time. I have been using Visual Studio 2003.NET. While VS2003 is okay for intellisense of ASP & Javascript, it's still not...
3
by: =?Utf-8?B?Tm9yZW1hYw==?= | last post by:
I have had no luck with the following scenario: One of our requirements for a particular business scenario is to test the existance of a URL before sending the client there. If the URL does not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.