referencing aspx pages in a class library

  • Thread starter Thread starter Ugo Van Noorbeeck
  • Start date Start date
U

Ugo Van Noorbeeck

Hi all,

I try to reference several pages from a class (ideally located in a class
library). But no namespace is available to do this.

Does anybody have an idea how to do this?

Thanks for your help,

Ugo
 
Hi all,
I try to reference several pages from a class (ideally located in a class
library). But no namespace is available to do this.

Does anybody have an idea how to do this?

Thanks for your help,

Ugo

What are you trying to do? You can't access them as you can with
winform-windows, where you can read values from hidden windows.
With webforms (asp.net) all page-values are gone as soon as the request
has finished processing.

You *can* get at the current Request or Session, using
System.Web.HttpContext.Current.Request (or .Session).
You will need a project-reference to System.Web.dll for this.


Hans Kesting
 
Hello,

In fact I want to be able to alter my page(s) with a "main controller" (the
class in the class library). I have several pages that differs only by one
textbox or so. And instead of creating new pages, I made a few "pattern
pages" in which I only hide/modify some controls depending on the page to
load. (I don't think Master page can help).
So, in the page_load (or just after) I call the method in the controller
class to make the adjustments. I pass the calling page as an argument but in
the code of the method this is a generic System.Web.UI.Page and I need to
cast it in the right "pattern page" type to access the controls.
There is where I need to reference the pages.

I hope it is a bit clearer.

Many thaks,

Ugo
 
Ugo,

You may want to pass the references to the pages to your class explicitly.
 
Yes, that's right but after, I have to dynamically cast the page into this
retrieved type. How can I do that? And how can the compiler let me call,
let's say: textbox1.enbled = false; onto a type that isn't known at compile
time?

One precision, I work in C#. If it is possible in VB that would be terrific!

Ugo


Eliyahu Goldin said:
Ugo,

You can always get the type name from the passed "page" parameter as

page.GetType().ToString();
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

Ugo Van Noorbeeck said:
Hello,

In fact I want to be able to alter my page(s) with a "main controller"
(the class in the class library). I have several pages that differs only
by one textbox or so. And instead of creating new pages, I made a few
"pattern pages" in which I only hide/modify some controls depending on
the page to load. (I don't think Master page can help).
So, in the page_load (or just after) I call the method in the controller
class to make the adjustments. I pass the calling page as an argument but
in the code of the method this is a generic System.Web.UI.Page and I need
to cast it in the right "pattern page" type to access the controls.
There is where I need to reference the pages.

I hope it is a bit clearer.

Many thaks,

Ugo
 
Ugo,

You can always get the type name from the passed "page" parameter as

page.GetType().ToString();
 
Yes, that's right but after, I have to dynamically cast the page into this
retrieved type. How can I do that? And how can the compiler let me call,
let's say: textbox1.enbled = false; onto a type that isn't known at compile
time?

One precision, I work in C#. If it is possible in VB that would be terrific!

Ugo

The Page has a "FindControl" method that you can use to find some
control by name. You can use this to see if there is a textbox named
"TextBox1". If so, cast the control that's found to TextBox and set
it's Visible property (or whatever you want to do with it).
One important note: this FindControl only finds immediate children (at
least in 1.1), so you might want to wrap this in a method that searches
the entire control-tree recursively.

Hans Kesting
Eliyahu Goldin said:
Ugo,

You can always get the type name from the passed "page" parameter as

page.GetType().ToString();
-- Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

Ugo Van Noorbeeck said:
Hello,

In fact I want to be able to alter my page(s) with a "main controller"
(the class in the class library). I have several pages that differs only
by one textbox or so. And instead of creating new pages, I made a few
"pattern pages" in which I only hide/modify some controls depending on the
page to load. (I don't think Master page can help).
So, in the page_load (or just after) I call the method in the controller
class to make the adjustments. I pass the calling page as an argument but
in the code of the method this is a generic System.Web.UI.Page and I need
to cast it in the right "pattern page" type to access the controls.
There is where I need to reference the pages.

I hope it is a bit clearer.

Many thaks,

Ugo



What are you trying to do? You can't access them as you can with
winform-windows, where you can read values from hidden windows.
With webforms (asp.net) all page-values are gone as soon as the request
has finished processing.

You *can* get at the current Request or Session, using
System.Web.HttpContext.Current.Request (or .Session).
You will need a project-reference to System.Web.dll for this.

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top