473,406 Members | 2,549 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,406 software developers and data experts.

Access property of parent webform from UC

Hello,

I have a user control which will be dynamically loaded from one of two
parent ASPX webforms. Within the user control I'd like to be able to access
a property from the parent webform. One problem I'm having is that I don't
know the type of the parent webform until run-time. Is this possible? And
if so, how can I do this?

Thank you,
Ben
Nov 19 '05 #1
4 3226
Hi,

Try this:

if (UserControl.Parent is <desired page-class name>)
{
//type cast Parent property and access the public property
}

"Ben Amada" <be*@REpoMOweVErpick.com> wrote in message
news:OY**************@TK2MSFTNGP15.phx.gbl...
Hello,

I have a user control which will be dynamically loaded from one of two
parent ASPX webforms. Within the user control I'd like to be able to access
a property from the parent webform. One problem I'm having is that I don't
know the type of the parent webform until run-time. Is this possible? And
if so, how can I do this?

Thank you,
Ben

Nov 19 '05 #2
Siva M wrote:
Hi,

Try this:

if (UserControl.Parent is <desired page-class name>)
{
//type cast Parent property and access the public property
}


Hi Siva,

Thank you for the good idea. I'm getting a couple of errors however while
trying to implement your idea in VB. Here's my code:

If Me.Parent Is WebForm6 Then
CType(Me.Parent, WebForm6).TestProp = "test"
End If

First error: The VS IDE is complaining about WebForm6 during design time.
It says:
"WebForm6 is a type and cannot be used as an expression."

Second error: If I eliminate the If-EndIf so I just have CType(...), then
during run-time, I get the following error:
"System.InvalidCastException: Specified cast is not valid."

WebForm6 is the parent ASPX page of this usercontrol, so I don't see why I'm
getting these errors.

Do you (or anyone else) have any idea what I'm doing wrong?

Thanks!
Ben
Nov 19 '05 #3
Ben,

Try it this way:

If TypeOf Me.Page Is WebForm6 Then
CType (Me.Page, WebForm6).TestProp = "text"
End If

One correction: It is Me.Page, not Me.Parent. Sorry about it.

"Ben Amada" <be*@REpoMOweVErpick.com> wrote in message
news:uq**************@tk2msftngp13.phx.gbl...
Siva M wrote:
Hi,

Try this:

if (UserControl.Parent is <desired page-class name>)
{
//type cast Parent property and access the public property
}


Hi Siva,

Thank you for the good idea. I'm getting a couple of errors however while
trying to implement your idea in VB. Here's my code:

If Me.Parent Is WebForm6 Then
CType(Me.Parent, WebForm6).TestProp = "test"
End If

First error: The VS IDE is complaining about WebForm6 during design time.
It says:
"WebForm6 is a type and cannot be used as an expression."

Second error: If I eliminate the If-EndIf so I just have CType(...), then
during run-time, I get the following error:
"System.InvalidCastException: Specified cast is not valid."

WebForm6 is the parent ASPX page of this usercontrol, so I don't see why I'm
getting these errors.

Do you (or anyone else) have any idea what I'm doing wrong?

Thanks!
Ben

Nov 19 '05 #4
Siva M wrote:
Ben,

Try it this way:

If TypeOf Me.Page Is WebForm6 Then
CType (Me.Page, WebForm6).TestProp = "text"
End If

One correction: It is Me.Page, not Me.Parent. Sorry about it.


Works great .. thanks again!

Ben
Nov 19 '05 #5

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

Similar topics

49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
3
by: PK | last post by:
Hi, I've a MDI form and a child form that comes from a dll. Everything works fine until I had to uncheck or check a menu item in the MDI form based on the changes in the child form. How to acheive...
4
by: SOS | last post by:
Hi guys , i create a custom control and place it on a web form, how can i access to this web form from my custom control ? for example i want to add a button to this webform by writing code in...
5
by: Steve Richter | last post by:
In my user control I want to read the ViewState dictionary of the Parent control. But this sensible idea is not permitted by the compiler: Compiler Error Message: CS1540: Cannot access...
3
by: Antuane | last post by:
hi guys, its me again, with a few simple (probably silly) quesetion... hi guys, i've managed to create a custom textbox class. & i'd like to access the parent control (in this case this would be...
4
by: Danny Tuppeny | last post by:
Hi all, The next few paragraphs put my question in context, but feel free to skip down to the end if you don't care *why* I need the answer! :) **************************************** ***...
10
by: Goran Djuranovic | last post by:
Hi all, Does anyone know how to declare a variable in a class to be accessible ONLY from a classes instantiated within that class? For example: ************* CODE ***************** Public...
2
by: jamesd | last post by:
I have a user control that has some simple textboxes. The user control is placed into a regular webform with a submit button on it. When the submit button is clicked, the form is posted to the...
7
by: adiel_g | last post by:
Hello Everyone, I created a custom control. On the CreateChildControls, I added a textbox to the control as follows: // TextBox TextBox txtValue = new TextBox(); txtValue.ID = "txtValue"; ...
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: 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
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.