Instantiate webform classes ....

G

Guest

How can I instantiate a webform2 object from webfrom1 codebehind? The class
does not popup in intellisense and gives me and error if i try to create it.

Nuno
 
G

Guest

A better option is move the common code to another class so you can call it
from both pages. While you can kludge things up to call webform 2 (different
methods depending on whether this is 1.1 or 2.0), it is, generally, not a
good option and I cannot think of any instance where you cannot move code to
another class alleviating the need for this type of kludge.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
G

Guest

Thanks for your response but that does not answer my question. What i wanted
to know was how to make the webforms and/or usercontrols visible to each
other.

I figured it out. Simply add an ASP.NET APP_CODE folder to your website and
create a abstract class within it that inherits the Page class. Then add
abstract public variables/objects you want to expose globally. Once you done
that, you have to modify your webform codebehind to inherit from the abstract
class that you created and create the corresponding properties.

Doing this in 1.1 was easy. Just change the modifier for whichever control
you want to expose.

/* this line in 2.0 is hidden from the programmer. I use this in 1.1 mainly
to expose the properties from controls in web user controls. */
public Label lblMsg = new Label();


It's a bit disappointing that i have to write more code now just to expose a
control's properties in an user control to a webform.

Nuno Pereira
 
S

Scott Allen

It's a bit disappointing that i have to write more code now just to expose a
control's properties in an user control to a webform.

Just use the @ Register directive. The @ Register directive will make
sure a user control's type (or a webform's type) is visible inside a
second code-beside file. The default compilation model in 2.0 will
make webforms invisible to each other.

Having said that, your architechture and maintenance is going to be
better off using an abstract base class or interface. The tight
coupling of two webforms or a web form and it's user controls leads to
pain and suffering in the future.

Here are some other thoughts I've had on the matter:

http://odetocode.com/Blogs/scott/archive/2006/02/07/2849.aspx
http://odetocode.com/Blogs/scott/archive/2005/06/30/1889.aspx
http://odetocode.com/Blogs/scott/archive/2005/06/29/1882.aspx
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top