473,503 Members | 10,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to reference control panels from other forms?

Hello Gurus,

At WebForm2, I am trying to set visible property of control panel
"Panel01" on WebForm1 to False. But I get error like "Instance not
referenced"

At WebForm2:
Dim wform As New WebForm2
wform.FindControl("Panel01").Visible = False

What is missing?

Aug 10 '06 #1
7 1060
Two things:

1. The default name is "Panel1" not "Panel01", so it may be too obvious
that this may not be the answer, but I thought I'd throw that out there.
2. You should dimension a Control and set that to the
Form.FindControl("MyControl") first, and then check if the value of your
Control is Nothing before trying to access any of its properties (this will
help you avoid explosive errors)

"Big Charles" wrote:
Hello Gurus,

At WebForm2, I am trying to set visible property of control panel
"Panel01" on WebForm1 to False. But I get error like "Instance not
referenced"

At WebForm2:
Dim wform As New WebForm2
wform.FindControl("Panel01").Visible = False

What is missing?

Aug 10 '06 #2
Thank you, Keith. Yes, you are right. Object gets as nothing. My
question would be: Why? What is missing in my variable declaration?
In my web form the name of control panel is "Panel01". I have another
control named ddlTipoOP as dropdownlist.

At WebForm2:
Dim wform as New WebForm1
Dim ctrl_1 As New DropDownList
Dim ctrl_2 As New Panel

ctrl_1 = CType(wform.FindControl("Panel01"), Panel)
ctrl_2 = CType(wform.FindControl("ddlTipoOP"),
DropDownList)

ctrl_1 gets Nothing
ctrl_2 gets Nothing

Aug 10 '06 #3
Declare Panel01 as "Public" in WebForm1 if you want to be able to access it
directly from another form.

"Big Charles" wrote:
Thank you, Keith. Yes, you are right. Object gets as nothing. My
question would be: Why? What is missing in my variable declaration?
In my web form the name of control panel is "Panel01". I have another
control named ddlTipoOP as dropdownlist.

At WebForm2:
Dim wform as New WebForm1
Dim ctrl_1 As New DropDownList
Dim ctrl_2 As New Panel

ctrl_1 = CType(wform.FindControl("Panel01"), Panel)
ctrl_2 = CType(wform.FindControl("ddlTipoOP"),
DropDownList)

ctrl_1 gets Nothing
ctrl_2 gets Nothing

Aug 10 '06 #4
Even if I declare in this way:

Public WithEvents Panel01 As System.Web.UI.WebControls.Panel

object still gets Nothing....

Keith wrote:
Declare Panel01 as "Public" in WebForm1 if you want to be able to access it
directly from another form.
Aug 10 '06 #5
web application don't work this way. a form class instance only exists
during the processing of that form, thus you can not set properties on
another form, as it does not exist. this where the stateless nature of web
processing must be handled. you can set a flag in session that the other
page checks to set the visibility.

in your example you created a new instance of WebForm2, but did not call the
processing routines (oninit, onload, etc...) and setup the html output
stream, so none of its sub controls are created. even if you call the
processing routines and set the property, it will have no impact on a later
page request.

-- bruce
"Big Charles" <ch**********@yahoo.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Hello Gurus,

At WebForm2, I am trying to set visible property of control panel
"Panel01" on WebForm1 to False. But I get error like "Instance not
referenced"

At WebForm2:
Dim wform As New WebForm2
wform.FindControl("Panel01").Visible = False

What is missing?

Aug 10 '06 #6
Still unsure of what you're trying to do. I was mixing up my windows forms
and my aspnet. In asp.net, the only form you can receive a control state
from is the current form. Use querystring, form, and session variables to
determine functionality between pages.

"Big Charles" wrote:
Even if I declare in this way:

Public WithEvents Panel01 As System.Web.UI.WebControls.Panel

object still gets Nothing....

Keith wrote:
Declare Panel01 as "Public" in WebForm1 if you want to be able to access it
directly from another form.

Aug 10 '06 #7
Remember...Webform1 is a class...your Webform1.aspx is a seperate class that
derived from Webform 1.

Webform1 has fields for each of the controls that you created, but they are
not set up in a hierarchy. The hierarchy is created when WebForm1.aspx is
compiled and then instantiated.

"Big Charles" wrote:
Hello Gurus,

At WebForm2, I am trying to set visible property of control panel
"Panel01" on WebForm1 to False. But I get error like "Instance not
referenced"

At WebForm2:
Dim wform As New WebForm2
wform.FindControl("Panel01").Visible = False

What is missing?

Aug 10 '06 #8

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

Similar topics

4
2736
by: Ron Vecchi | last post by:
Could someone point me in the right direction for creating a control similar to the VS solution explorer where it will auto hide and open when needed. Thanks -- Ron Vecchi
1
7646
by: pfnus | last post by:
Hi, I want to display different forms when the buttons are clicked and all the forms are having different controls on it. So instead of adding new windows forms to the project, i enlarged the...
6
3067
by: J.S. | last post by:
I have a TreeView control in the left panel of a SplitContainer. When I click on various nodes in the TreeView I would like different sets of buttons and textboxes to appear in the right panel. ...
2
1199
by: jm | last post by:
I have datagrid. Inside the template columms there is a textbox. It has an id. When the textbox wasn't inside the datagrid tags, I could reference with order_id.text = "some text" but all of a...
6
14673
by: Selden McCabe | last post by:
I have a form with a bunch of image buttons. When the user moves the mouse over a button, I want to do two things: 1. change the Imagebutton's picture, and 2. make another control visible. I'm...
0
1010
by: Juan Pedro Gonzalez | last post by:
Hi, I'm running mad with this issue, hope I can explain it correctlly. I've been developping a user control wich is very similar to the TabControl... Basically my control has two panels that...
3
1787
by: Rain | last post by:
hi, im displaying around 30 user controls, small panels to be specific, in one form. the problem is when displaying, it displays the panels one at a time. I mean you can literally see them being...
2
1324
by: johnb41 | last post by:
I want to create a textbox programmatically and add the SAME textbox to to different panels. This code does not work: Dim tb As New TextBox tb.text = "xyz" Panel1.Controls.Add(tb)...
1
1937
by: johnson.bj | last post by:
I have a relatively minor problem that has been bugging me for a long time. I have created a user control which consists of a few panels and labels. What I want to do with this user control is to...
0
7207
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
7294
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,...
0
7361
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...
0
7470
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...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3183
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...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
403
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...

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.