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

Home Posts Topics Members FAQ

Instantiate webform classes ....

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
Feb 14 '06 #1
3 1597
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!
*************** ************
"Nuno" wrote:
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

Feb 14 '06 #2
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
"Cowboy (Gregory A. Beamer) - MVP" wrote:
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!
*************** ************
"Nuno" wrote:
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

Feb 14 '06 #3
On Tue, 14 Feb 2006 11:14:27 -0800, "Nuno"
<Nu**@discussio ns.microsoft.co m> wrote:


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/arc...2/07/2849.aspx
http://odetocode.com/Blogs/scott/arc...6/30/1889.aspx
http://odetocode.com/Blogs/scott/arc...6/29/1882.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/
Feb 15 '06 #4

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

Similar topics

2
2478
by: jerrygarciuh | last post by:
Hello, Is it possible to instantiate a child class within the constructor of its parent? eg Class DBI extends DB { function DBI() { // explicit parent constructor call
5
2036
by: Jerry | last post by:
I am using .Net 2003. I have been working with this ASP.Net webform that I created a few weeks ago. It has been working fine. However, while modifying the webform today, this webform stopped working and now only gives me the following error message. I was only modifying the webform code, nothing else. But now my webform won't display in a browser. What can I do?
6
1121
by: Tom | last post by:
Hi, I built an aspx page with c#. There are many textbox and a submit button. When I input data in form and click submit, I saw their values are null in debug window. I checked namespace is correct. What is the potential bug in my program?
8
1663
by: Keith-Earl | last post by:
Okay, looking for a Best Practice. We are building a classic three tier app in VB.NET. When we load up a WebForm we have access to very useful objects such as the Session object. We frequently store short lists in Session or even Application objects and retrieve them later without having to make a round trip to the db. We think the best place to do all this is in the Business tier and not to clutter up the client (WebForm). In order...
0
959
by: Angel | last post by:
i would like the comunity's opinion on validating a Webform. I was wondering should i validate data that the user enters on a Webform via a Backend process like SQL Server 2000 or should I use Javascript to validate the data? Or is there another option such as creating .neT classes? I can use Javascript files to validate the data. If I use this method I eliminate of having to go to the server, validate the data, then come back and redraw...
7
2072
by: Daniel Nogradi | last post by:
What is the simplest way to instantiate all classes that are subclasses of a given class in a module? More precisely I have a module m with some content: # m.py class A: pass class x( A ): pass
1
1622
by: Donald Westfield | last post by:
I have my own module, called mystuff.py, which is to be imported for an app. The number of classes in the module will vary, so I need a subroutine that will instantiate all of them as objects, and assign a variable to each, regardless of what names the classes are. Then I need to be able to delete these objects from memory completely at times.
5
4529
by: Pyenos | last post by:
class One: Two() #can't instantiate class Two: Three() #can't instantiate class Three:pass
7
3238
by: Joe Strout | last post by:
I have a function that takes a reference to a class, and then instantiates that class (and then does several other things with the new instance). This is easy enough: item = cls(self, **itemArgs) where "cls" is the class reference, and itemArgs is obviously a set of keyword arguments for its __init__ method. But now I want to generalize this to handle a set of mix-in classes.
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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,...
0
8730
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
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
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
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1607
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.