473,471 Members | 4,637 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Casting to parent page from user control - how??

I got a particular problem in visual studio 2005
There's a user control on page and I want to meka a cast like this

MyPage mp=(MyPage)this.Page;

Error is : cannot cast from ASP.mypage_blalala_aspx to MyPage.
Stupid namespace ASP doesn't have that class name.
I can't even put any base classes to that crazy App_Code folder
to get the class reference. Am I doing something wrong?
All I want to do is during click to access a mainpage method from user control
that is on a gridview. Or how to simply tell a parent page that one of
user controls raised some event. There can be many user controls on the grid.
What's the point of blocking the page classes?
How to get rid of this terrible App_code folder and make things work?
I beg for help. Thanks.

Eric
Nov 21 '06 #1
4 7575
I agree it's annoying, but there are good solutions available...

1 -
In the user control you can use the @reference directive to make the type
available, something like:

<%@ Reference Page="~/about.aspx" %>

which should make the cast work...

problem with this is that it ties your user control to that particular
page - which defeats part of the purpose of using a user control...

2 -
Using an interface or a base class in the app_code is the right way to do it
(unless you go with #3). This is the ASP.NET team's attempt to force
developers to code better (which in theory I agree with). I'm not sure why
you are having problems with this...but I myself find it a little annoying
and generally prefer #3.
3 -
Using the Web Application Project which you can (freely) download from:
http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx

Once installed, you can create new web applications projects which behave A
LOT more like everything worked in 2003. I use this almost exclusively for
anything that's midly complicated (as far as structure goes). You'll have
to restart your project though..copy and pasting should mostly work :)

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Eric" <sp**@spam.nowrote in message
news:e4**************@TK2MSFTNGP04.phx.gbl...
>I got a particular problem in visual studio 2005
There's a user control on page and I want to meka a cast like this

MyPage mp=(MyPage)this.Page;

Error is : cannot cast from ASP.mypage_blalala_aspx to MyPage.
Stupid namespace ASP doesn't have that class name.
I can't even put any base classes to that crazy App_Code folder
to get the class reference. Am I doing something wrong?
All I want to do is during click to access a mainpage method from user
control
that is on a gridview. Or how to simply tell a parent page that one of
user controls raised some event. There can be many user controls on the
grid.
What's the point of blocking the page classes?
How to get rid of this terrible App_code folder and make things work?
I beg for help. Thanks.

Eric
Nov 22 '06 #2
Thanks Karl.
Do you know if there are any particular advantages using
Web Site Project model versus Web Application Project model?
The first one enforces many limits for coding which I'd say
doesn't make it a better coding. OOP concept is all about
managing variety of many objects which now are removed.
User controls sometimes if not mostly have purpose
of eliminating large number of identical objects that
perform different functions in the base class that is our page class.
Accessing methods is easy, event objects get destroyed on the roundtrips
so it's hard to say what is really better.
BTW any reference to page from user.c. causes circular reference error
an in fact there is a namespace to page but hidden and disabled in VS2005)
Thanks for help.

Eric

"Karl Seguin" <ka********@removeopenmymindremovemetoo.andmenetwr ote in message news:%2****************@TK2MSFTNGP06.phx.gbl...
>I agree it's annoying, but there are good solutions available...

1 -
In the user control you can use the @reference directive to make the type
available, something like:

<%@ Reference Page="~/about.aspx" %>

which should make the cast work...

problem with this is that it ties your user control to that particular
page - which defeats part of the purpose of using a user control...

2 -
Using an interface or a base class in the app_code is the right way to do it
(unless you go with #3). This is the ASP.NET team's attempt to force
developers to code better (which in theory I agree with). I'm not sure why
you are having problems with this...but I myself find it a little annoying
and generally prefer #3.
3 -
Using the Web Application Project which you can (freely) download from:
http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx

Once installed, you can create new web applications projects which behave A
LOT more like everything worked in 2003. I use this almost exclusively for
anything that's midly complicated (as far as structure goes). You'll have
to restart your project though..copy and pasting should mostly work :)

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Eric" <sp**@spam.nowrote in message
news:e4**************@TK2MSFTNGP04.phx.gbl...
>>I got a particular problem in visual studio 2005
There's a user control on page and I want to meka a cast like this

MyPage mp=(MyPage)this.Page;

Error is : cannot cast from ASP.mypage_blalala_aspx to MyPage.
Stupid namespace ASP doesn't have that class name.
I can't even put any base classes to that crazy App_Code folder
to get the class reference. Am I doing something wrong?
All I want to do is during click to access a mainpage method from user
control
that is on a gridview. Or how to simply tell a parent page that one of
user controls raised some event. There can be many user controls on the
grid.
What's the point of blocking the page classes?
How to get rid of this terrible App_code folder and make things work?
I beg for help. Thanks.

Eric
Nov 22 '06 #3
Yes, there are some advantages. The Web site project is much more flexible
when it comes to deployment...you can fully pre-compile your site (you can
do that with the other one too actually), you can compile none of your site
or you can just compile your source code. For some people, this is a key
benefit.

There's also no .proj file, which in some cases is great, and in some cases
isn't...

It's really give and take..but like I said, for my apps I tend to prefer the
WAP..

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Eric" <sp**@spam.nowrote in message
news:u5*************@TK2MSFTNGP06.phx.gbl...
Thanks Karl.
Do you know if there are any particular advantages using Web Site Project
model versus Web Application Project model?
The first one enforces many limits for coding which I'd say doesn't make
it a better coding. OOP concept is all about
managing variety of many objects which now are removed.
User controls sometimes if not mostly have purpose
of eliminating large number of identical objects that perform different
functions in the base class that is our page class.
Accessing methods is easy, event objects get destroyed on the roundtrips
so it's hard to say what is really better.
BTW any reference to page from user.c. causes circular reference error
an in fact there is a namespace to page but hidden and disabled in VS2005)
Thanks for help.

Eric

"Karl Seguin" <ka********@removeopenmymindremovemetoo.andmenetwr ote in
message news:%2****************@TK2MSFTNGP06.phx.gbl...
>>I agree it's annoying, but there are good solutions available...

1 -
In the user control you can use the @reference directive to make the type
available, something like:

<%@ Reference Page="~/about.aspx" %>

which should make the cast work...

problem with this is that it ties your user control to that particular
page - which defeats part of the purpose of using a user control...

2 -
Using an interface or a base class in the app_code is the right way to do
it (unless you go with #3). This is the ASP.NET team's attempt to force
developers to code better (which in theory I agree with). I'm not sure
why you are having problems with this...but I myself find it a little
annoying and generally prefer #3.
3 -
Using the Web Application Project which you can (freely) download from:
http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx

Once installed, you can create new web applications projects which behave
A LOT more like everything worked in 2003. I use this almost exclusively
for anything that's midly complicated (as far as structure goes). You'll
have to restart your project though..copy and pasting should mostly work
:)

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Eric" <sp**@spam.nowrote in message
news:e4**************@TK2MSFTNGP04.phx.gbl...
>>>I got a particular problem in visual studio 2005
There's a user control on page and I want to meka a cast like this

MyPage mp=(MyPage)this.Page;

Error is : cannot cast from ASP.mypage_blalala_aspx to MyPage.
Stupid namespace ASP doesn't have that class name.
I can't even put any base classes to that crazy App_Code folder
to get the class reference. Am I doing something wrong?
All I want to do is during click to access a mainpage method from user
control
that is on a gridview. Or how to simply tell a parent page that one of
user controls raised some event. There can be many user controls on the
grid.
What's the point of blocking the page classes?
How to get rid of this terrible App_code folder and make things work?
I beg for help. Thanks.

Eric
Nov 23 '06 #4
Eric,
As Karl "kinda" alluded, I personally don't even use website projects
anymore. I find the new WAP model to be far preferable. I'm talking about
production applications for public websites here.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Eric" wrote:
Thanks Karl.
Do you know if there are any particular advantages using
Web Site Project model versus Web Application Project model?
The first one enforces many limits for coding which I'd say
doesn't make it a better coding. OOP concept is all about
managing variety of many objects which now are removed.
User controls sometimes if not mostly have purpose
of eliminating large number of identical objects that
perform different functions in the base class that is our page class.
Accessing methods is easy, event objects get destroyed on the roundtrips
so it's hard to say what is really better.
BTW any reference to page from user.c. causes circular reference error
an in fact there is a namespace to page but hidden and disabled in VS2005)
Thanks for help.

Eric

"Karl Seguin" <ka********@removeopenmymindremovemetoo.andmenetwr ote in message news:%2****************@TK2MSFTNGP06.phx.gbl...
I agree it's annoying, but there are good solutions available...

1 -
In the user control you can use the @reference directive to make the type
available, something like:

<%@ Reference Page="~/about.aspx" %>

which should make the cast work...

problem with this is that it ties your user control to that particular
page - which defeats part of the purpose of using a user control...

2 -
Using an interface or a base class in the app_code is the right way to do it
(unless you go with #3). This is the ASP.NET team's attempt to force
developers to code better (which in theory I agree with). I'm not sure why
you are having problems with this...but I myself find it a little annoying
and generally prefer #3.
3 -
Using the Web Application Project which you can (freely) download from:
http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx

Once installed, you can create new web applications projects which behave A
LOT more like everything worked in 2003. I use this almost exclusively for
anything that's midly complicated (as far as structure goes). You'll have
to restart your project though..copy and pasting should mostly work :)

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Eric" <sp**@spam.nowrote in message
news:e4**************@TK2MSFTNGP04.phx.gbl...
>I got a particular problem in visual studio 2005
There's a user control on page and I want to meka a cast like this

MyPage mp=(MyPage)this.Page;

Error is : cannot cast from ASP.mypage_blalala_aspx to MyPage.
Stupid namespace ASP doesn't have that class name.
I can't even put any base classes to that crazy App_Code folder
to get the class reference. Am I doing something wrong?
All I want to do is during click to access a mainpage method from user
control
that is on a gridview. Or how to simply tell a parent page that one of
user controls raised some event. There can be many user controls on the
grid.
What's the point of blocking the page classes?
How to get rid of this terrible App_code folder and make things work?
I beg for help. Thanks.

Eric
Nov 23 '06 #5

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

Similar topics

2
by: Russell | last post by:
Morning, I have been having trouble with a my embedded user control not being able to see the view state that I set in its parent page. I have done a test with the following and I still cant...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
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...
1
by: David Lozzi | last post by:
Hello, I have a user control that saves data. When the data is saved, I need to call a function in the parent page from the user control to initiate something else. I know I can set it up so...
2
by: engwar1 | last post by:
I have a page that my users will go to to upload files to my website. As I want to reuse the file upload code on multiple pages I put the file upload textbox/buttons on a user control which I plan...
5
by: Josh Nikle | last post by:
I have a webform containing a GridView control "GridView1" and usercontrol which is also a GridView "GridView2." I have a button column in the usercontrol. The code behind that button adds an...
5
by: gnewsgroup | last post by:
In my user control, I would like to find a Label control in the parent page (the page that uses my user control). I need to update that Label.Text when something happens in the user control. I...
0
by: CMELLO | last post by:
I have am dynamically loading a web user control based on the click of a tab strip I load the default control for the first tab in the page load event after checking page is not postback. After...
0
by: =?Utf-8?B?Y2luZHk=?= | last post by:
I have am dynamically loading a web user control based on the click of a tab strip I load the default control for the first tab in the page load event after checking page is not postback. After...
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
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
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
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...
1
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
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,...
0
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
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.