Hello,
I am trying to add the following to a App_Code class. The error I am
getting references "Page.Controls" . I would like to call this from my
content page which uses MasterPages
I read the following from Steven Cheng, but am having a hard time following:
In ASP.NET 2.0, the pages and usercontrols and their codebehind classes are
dynamically compiled at runtime. However, the dynamic compilation is
possible to compile the page or usercontrols's class into separate
assemblies(due to the folder structure and location of the page and
usercontrols). Thus, in your utility class (you put in App_Code or an
external assembly), it will not see those page/usercontrol classes(compile d
in a different dynamic compiled assembly). For your scenario, you want to
reference some certain usercontrol through their concrete type, I think you
may consider defining some base usercontrol class for your usercontrols,
these base classes can be put in App_Code source files or in an external
assembly(class library project), then you can make the usercontrols(in your
web application) derive from those base classes, e.g.
=============
public partial class usercontrols_He lloUC : MyBaseUserContr olClass
{
............... .........
}
=============
Thus, you can reference the usercontrol instance type the base class type in
your utility class.
.. Any help with this would be appreciated...
sck10
public void SecurityHidePan els()
{
foreach (Control ctlMaster in Page.Controls)
{ // Page
if (ctlMaster is MasterPage)
{ // MasterPage
foreach (Control ctlForm in ctlMaster.Contr ols)
{
if (ctlForm is HtmlForm)
{ // HtmlForm
foreach (Control ctlContent in ctlForm.Control s)
{
if (ctlContent is ContentPlaceHol der)
{ // ContentPlaceHol der
foreach (Control ctlChild in ctlContent.Cont rols)
{ //Hide All Panel
if (ctlChild is Panel)
{
ctlChild.Visibl e = false;
}
}
}
}
}
}
}
}
} 5 1819
Hello Steve,
From the code and error info you provided, I can get that you're creating a
custom helper class(put in App_code directory) and it the custom class's
method, you directly use the Page class and its members to loop through the
page's control collection ,but encountered errors, correct?
As for the App_Code, the class put in it is just normal custom classes,
they has not particular context and is as normal as other custom classes
put in a separate Class Library project. Therefore, if you want to define
a custom Helper class that loop through Page's control collection, I
suggest you define the method to accept an input parameter of Page class ,
e.g:
public class HelperClass
{
public void LoopControlsInP age(Page page)
{
............... .
}
}
BTW, are you using this custom class in page's codebehind? If this is the
case, it is easy to get the Page's reference and pass it into such custom
helper function.
In addition, since you're writing code to loop through the Page's control
collection, I suggest you turn on the Page's output Trace which will
display the pages' complete Control Tree at the bottom of the page output
..e.g.
<%@ Page ............... ..... Trace="true" %>
this is quite useful at development/test time.
Hope this helps. Please let me know if you have anything unclear or
anything else you wonder.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks Steven,
How would you supply the page when calling this from a content page?
class_General.S ecurityHidePane ls(?????);
Thanks, sck10
"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:yL******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hello Steve,
From the code and error info you provided, I can get that you're creating
a
custom helper class(put in App_code directory) and it the custom class's
method, you directly use the Page class and its members to loop through
the
page's control collection ,but encountered errors, correct?
As for the App_Code, the class put in it is just normal custom classes,
they has not particular context and is as normal as other custom classes
put in a separate Class Library project. Therefore, if you want to define
a custom Helper class that loop through Page's control collection, I
suggest you define the method to accept an input parameter of Page class ,
e.g:
public class HelperClass
{
public void LoopControlsInP age(Page page)
{
............... .
}
}
BTW, are you using this custom class in page's codebehind? If this is the
case, it is easy to get the Page's reference and pass it into such custom
helper function.
In addition, since you're writing code to loop through the Page's control
collection, I suggest you turn on the Page's output Trace which will
display the pages' complete Control Tree at the bottom of the page output
e.g.
<%@ Page ............... ..... Trace="true" %>
this is quite useful at development/test time.
Hope this helps. Please let me know if you have anything unclear or
anything else you wonder.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.
Hi Steve,
We can use the "Page" property as long as the code is executing in a
certain pages' code(no matter it is Master Page or Content page derived
from a master). Actually, for content page, it will include the master
page(it applies ) as a child control.
For example, in the content page's Page_Load event, you can call your
helper class's function as below:
void Page_Load(..... )
{
class_General.S ecurityHidePane ls( this.Page );
}
Please let me know if this helps or if you have any particular concerns
here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Steven,
I finally figured it out last night. Thanks for all your help though.
Moving from vb to c# has been somewhat of a struggle (smile).
Cheers....
"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:hA******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi Steve,
We can use the "Page" property as long as the code is executing in a
certain pages' code(no matter it is Master Page or Content page derived
from a master). Actually, for content page, it will include the master
page(it applies ) as a child control.
For example, in the content page's Page_Load event, you can call your
helper class's function as below:
void Page_Load(..... )
{
class_General.S ecurityHidePane ls( this.Page );
}
Please let me know if this helps or if you have any particular concerns
here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.
Hi Steve,
Glad that you've figured it out. I've seen some guys suggest you the
"Reflector" tool, I also agree that it is a good tool if you have some code
of a single language want to convert it to other different .net languages.
Good luck!
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: AZ |
last post by:
During the Pre-compile process of an ASP.Net 2.0 app, it compiles the
code-behind & optionally the presentation files into an assembly named
App_Code.dll. Can that not be renamed to a more project friendly name, such
as ProjectName.dll or something. I didnt see any parameters to be able to
choose the output assembly name.
|
by: Jay Douglas |
last post by:
I have a set of pages that inherit from a base class in the App_Code folder.
The class looks something like:
public class MyBaseClass : System.Web.UI.Page
In various stages of the life cycle I need to add user controls to the page
control container. i.e:
protected override void OnInit(EventArgs e)
{
|
by: hummh |
last post by:
Hello out there,
I´m making my first steps with ASP.NET 2.0 and have he following
problem:
I´ve implemented a Web User Control that sits in the root of my
ASP.NET Website. I want to use the Type of the control in a class
that´s under the App_code folder. As with ASP.NET 1.x, I tried to
reference the Control via the using keyword - but that didn´ t work,
because the Web User Control has no namespace (VS.NET didn´t add one).
|
by: walter |
last post by:
Hi, when I add a new page in my asp.net 2 project and put some controls
there, everything works fine until I move the code behind into App_Code
folder.--When I compile , it tells me that control "not exist in the current
context".
I thought putting code behind in App_Code folder is the recommendation for
asp.net 2. In order to do so, I just simply remove the codefile attribute in
@page.
Maybe my perception of putting all code in...
|
by: motorhead_maniac |
last post by:
anyone,
how to reference server controls (without .ascx) that are in the
app_code folder.
The msdn documentation talks about dropping them in and using Page
section of web.config to add and specify Namespace , but iam not able to
figure out their Namespace
Many thanks
| |
by: Martin Simard |
last post by:
Hi all,
Is there a way to rename the App_Code.dll generated from the code that
belongs to the App_Code folder?
We are developping several web applications that we are merging in a single
application on our production server. This works great with the new
compilation model of .NET 2.0, but we have to create a class library for
each web application to have a unique .dll for each app. Each class library
has a unique name since it...
|
by: sck10 |
last post by:
Hello,
I am converting a class in the App_Code folder from c# to vb and am having
problems calling the sub procedure. I have created a Sub called HidePanels
in the class "General". When I try to declare a new object of this type in
my codebehind, I get the error: "Type 'HidePanels' is not defined". Any
help with this would be appreciated. Thanks, sck10
code behind
===========
|
by: rn5a |
last post by:
Is putting a VB class file in the special directory named App_Code the
same as relocating the VB class file from the App_Code directory to
another directory & then using the VBC tool, compiling the VB class
file into a DLL & putting the DLL in the bin directory?
Though while running an ASP.NET app using either of the 2 approaches
doesn't make any difference, Visual Web Developer 2005 Express Edition
behaves erratically sometimes if the...
|
by: netasp |
last post by:
hi all,
when adding a new web form in VS 2003, usually viewing the code behind for
that form will let you write any method or function and referencing any web
control placed on the form without any problems, for example writing a
function that grabs a string value from a textbox is as easy as saying:
dim str as string = me.TextBox1.Text
but with visual studio 2005 I can't do this in the simple way because the
class for
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |