473,657 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3238
Hi,

Try this:

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

"Ben Amada" <be*@REpoMOweVE rpick.com> wrote in message
news:OY******** ******@TK2MSFTN GP15.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.Pa rent 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).TestP rop = "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.Invalid CastException: 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).TestP rop = "text"
End If

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

"Ben Amada" <be*@REpoMOweVE rpick.com> wrote in message
news:uq******** ******@tk2msftn gp13.phx.gbl...
Siva M wrote:
Hi,

Try this:

if (UserControl.Pa rent 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).TestP rop = "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.Invalid CastException: 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).TestP rop = "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
14324
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 application is relatively big: around 200 tables, 200 forms and sub-forms, 150 queries and 150 repports, 5GB of data (SQL Server 2000), 40 users. I'm wondering what are the disadvantages of using Access as front-end? Other that it's not...
3
5583
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 this ? How can a child form (that is in dll) access a menuitem in the main form ? Pl. help.
4
1392
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 my custom control. Thanx :)
5
7660
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 protected member 'System.Web.UI.Control.ViewState' via a qualifier of type 'System.Web.UI.Control'; the qualifier must be of type 'ASP.ItemOrderGrid' (or derived from it) Source Error:
3
1841
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 the form, cuz i drop the textbox onto the form), in the constructor of the custom textbox class. i'd like to access the parent control in the constructur of the textbox. But i can't do this, cuz i get an error, saying that the parent property...
4
1353
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! :) **************************************** *** Start of long-winded description *** **************************************** I've got some classes that define a tree structure. When the Parent
10
19608
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 Class Parent '*** HOW TO DECLARE IT *** Dim Age As String = "1/1/2000"
2
1961
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 server. The user control contains some code to SERVER SIDE validate one of the textboxes. IF the validation fails, i want the parent web form to know about it, and display a message on the screen.
7
3072
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"; protected override void CreateChildControls() { // Add the control to the form
0
8838
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...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7351
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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...
1
2740
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
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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.