Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call code from another page

Status
Not open for further replies.

ASPnetNovice

Programmer
Apr 28, 2005
19
US
Hello,

I was wondering if someone knows how to call code from a sibilling page.

I have 6 asp.net pages for an online questionaires and from page 3 I need to call code that was written in page 1.

The approach I am using is as follows.

the code behind from page 1 comes from a class call page 1

So what I am doing is declaring

Dim p1 as new page1 inside page 3 and hope to use the functions declare in page1

but for some reason this is giving me the following error

"Object reference not set to an instance of an object"

The code in page 1 trys to get info about controls inside page1 using Me.FindControl("Form1ID")

I will appreciate any help

Thanks.
 
Why don't you place the code that you need to access from various pages, into a class or function?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I might think of a different way to do this like put the value you need on page3 into session while on page1. The page classes really weren't meant to do what your doing.
 
Yes in the long run I will need to move that code to a class (that will implie a redesign of some functions and passing more parameters) but for know I need a quick fix.

I am sure it must be a way to call code from another page it seems like something people will do frequently ?
 
I've never done what you are attempting. Knowing what I know about the Page Lifecycle, instanciating one page from another to me seems risky and like hitting a tack with a sledge hammer.

Sometimes faster is slower, and todays quick fix is tomorrow problem. If other members also instanciate one page from another, go for it, but I would recommend against that.
 
Classes are not only the correct way, but it is "a quick fix" as you say. It is easier to create a class and use it properly then trying to do it your way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top