473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How can I bind two forms?

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
Nov 19 '05 #1
5 1290
Steven wrote:
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...._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

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #2
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


"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:uP****************@TK2MSFTNGP09.phx.gbl...
Steven wrote:
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...._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

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 19 '05 #3
KMA
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.
So theoritically, I 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" <counterball_20122@_hotmail.com> wrote in message
news:#c**************@TK2MSFTNGP15.phx.gbl... 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


"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:uP****************@TK2MSFTNGP09.phx.gbl...
Steven wrote:
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...._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

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Nov 19 '05 #4
KMA wrote:
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.

So theoritically, I


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" <counterball_20122@_hotmail.com> wrote in message
news:#c**************@TK2MSFTNGP15.phx.gbl...
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


"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:uP****************@TK2MSFTNGP09.phx.gbl.. .
Steven wrote:

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...._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

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET



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...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #5
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
"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:eH*************@TK2MSFTNGP12.phx.gbl...
KMA wrote:
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.

So theoritically, I

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" <counterball_20122@_hotmail.com> wrote in message
news:#c**************@TK2MSFTNGP15.phx.gbl...
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


"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:uP****************@TK2MSFTNGP09.phx.gbl. ..

Steven wrote:

>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...._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

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


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...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 19 '05 #6

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

Similar topics

2
by: Andrew J. Kelly | last post by:
How do you data bind to a group of radio buttons? I can bind to an individual radio button just fine but how do you bind a single field to all the buttons so it works like a Radio button should? ...
2
by: Pete Nelson | last post by:
Does anyone know of a way to bind a string collection to a datagrid? Basically, I have an object, CreditPlans, and a string collection, ModelNumbers. I'd like to bind the ModelNumbers collection...
4
by: Greg Linwood | last post by:
I am wondering what the best approach to binding XML data to an asp:Table from the Page_Load event in a code behind module? I'm using VB.Net and initially approached this by adding a table to the...
3
by: AH | last post by:
Hi all, I noticed this strange behavior; I created a new control (example inherits from textbox) and add a new property, then I bind this new property to a field in my dataTable in a dataSet....
1
by: john wright | last post by:
I have a dictionary oject I created and I want to bind a listbox to it. I am including the code for the dictionary object. Here is the error I am getting: "System.Exception: Complex...
1
by: Eric | last post by:
I wrote a query in Form_Open method but i didnt bind it with the textbox. How to i bind this whole method with the text box, as right now the textbox shows the last value of the recordset. The...
2
by: Mikus Sleiners | last post by:
I have a control - textBox1 that is binded to objects propery - "Currency" and another control - textBox2 (read only) that is also binded to same propery. Now, i have a situation where textbox1...
2
by: deekay | last post by:
Im trying to update a database where our users have been entering/editing all data using queries to now use forms instead. The first step that I want to take is to convert the queries to forms in...
3
by: teddysnips | last post by:
Back in the dim mists of antiquity I used to program in VBA for Microsoft Access (hey, don't knock it - very useful tool for the right application). This had a really handy control in the...
2
by: Ronald S. Cook | last post by:
Does anyone know why an IEnumerable might not bind to a DataGridView? Thanks, Ron
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.