How can I bind two forms?

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

I'm using C# as code-behind for my aspx pages. How can I bind pages..
so that both the pages can use the functions, variables, controls .. between
each other.

eg., if I declare function scope() in page1, I should be able to use it in
page2 and vice-versa. same with variable also..

Any help would be grealty apprecited!

Thanks
Steven
 
Steven said:
I'm using C# as code-behind for my aspx pages. How can I bind pages..
so that both the pages can use the functions, variables, controls .. between
each other.

eg., if I declare function scope() in page1, I should be able to use it in
page2 and vice-versa. same with variable also..

Any help would be grealty apprecited!

Thanks
Steven
Create one .aspx.cs classfile and then change the Inherits attribute
value on the Page directive as appropriate:

http://www.aspsmith.com/viewarticle.aspx?paged_article_id=42

If using VS.NET, note it normally creates a different code-behind file
for each .aspx, but there's no reason you can't change that attribute to
point at a different (shared) .aspx.cs
 
I have 2 pages (mainform.aspx and print.aspx). As in your article I chaged
the code-behind for print.aspx to mainform.aspx.cs. So theoritically, I
should be able to access the control mainbut (Main button) from my
print.aspx page. But I'm unable to do that. What is wrong in my approach?

please help !

Thanks
Steven
 
I'm quite new to this stuff so I'm only guessing......


... but if you inherit from the same code begind class doesn't each page get
its' own instance of the button? What you need is to get some kind of
reference/handle to the mainpage from the printpage.
should be able to access the control mainbut (Main button) from my
print.aspx page

I don't think so. When you write
mainbut.text = "change, damn your hide!";

you are really writing:
self.mainbut.text = "change, damn your hide!";

which is the same as:
printpage.mainbut.text = "change, damn your hide!";

and if your printpage doesn't have a rendered control called mainbut then
not much will happen.

I'm afraid I can't really see what you want to do. I guess you have a main
page which spawns the print page, and when this finishes printing you want
to disable the print button or something. The thing is I don't understand
how you think both pages will be active at the same time in the app
lifecycle, other than in two (tabs?) browsers.

To get the main page to show any state that recently changed in the print
page then you must somehow trigger a refresh which looks at a common
variable.

I'm intrigued by the problem but I don't have a quick solution.





Steven said:
I have 2 pages (mainform.aspx and print.aspx). As in your article I chaged
the code-behind for print.aspx to mainform.aspx.cs. So theoritically, I
should be able to access the control mainbut (Main button) from my
print.aspx page. But I'm unable to do that. What is wrong in my approach?

please help !

Thanks
Steven
 
KMA said:
I'm quite new to this stuff so I'm only guessing......


.. but if you inherit from the same code begind class doesn't each page get
its' own instance of the button? What you need is to get some kind of
reference/handle to the mainpage from the printpage.

should be able to access the control mainbut (Main button) from my
print.aspx page


I don't think so. When you write
mainbut.text = "change, damn your hide!";

you are really writing:
self.mainbut.text = "change, damn your hide!";

which is the same as:
printpage.mainbut.text = "change, damn your hide!";

and if your printpage doesn't have a rendered control called mainbut then
not much will happen.

I'm afraid I can't really see what you want to do. I guess you have a main
page which spawns the print page, and when this finishes printing you want
to disable the print button or something. The thing is I don't understand
how you think both pages will be active at the same time in the app
lifecycle, other than in two (tabs?) browsers.

To get the main page to show any state that recently changed in the print
page then you must somehow trigger a refresh which looks at a common
variable.

I'm intrigued by the problem but I don't have a quick solution.





I have 2 pages (mainform.aspx and print.aspx). As in your article I chaged
the code-behind for print.aspx to mainform.aspx.cs. So theoritically, I
should be able to access the control mainbut (Main button) from my
print.aspx page. But I'm unable to do that. What is wrong in my approach?

please help !

Thanks
Steven





value

for

point
I thought you were referring to sharing the code, not actual instances
of controls/objects. The actual page/control instances are created for
each request. What are you trying to do? Share code, or share actual
runtime objects? Or do something on the client-side (click a button, etc.)?

If you wanted to populate a variable on one page and access it in
another, you should pass it via the querystring, or session, or
cache...many ways to persist values for retrieval on other pages...
 
Allright, I think I found some solution for this ..
I want access GetURL class (which is declared in mainform.aspx) from
show.aspx.

I declared this in my mainform.aspx.cs on page_load event:

show oshow = new show() ;
oshow.PerformHandShake(this) ;

and in show.aspx, I'm trying to access the class GetURL like:

protected mainform MainFormPointer:

public void PerformHandShake(mainform mainfptr)
{
this.MainFormPointer = mainfptr;
}

private void Page_Load(object sender, System.EventArgs e)
{
String Main = " Show Me";
string post = this.MainFormPointer.GetURL(Main); --> Line 8
}

When I try to run this code, error is popping up saying " Object Reference
not set to an instance of the object" in Line 8. What could be the error?

Thanks
Steven
 
Back
Top