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

Home Posts Topics Members FAQ

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 1302
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.c s. 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_SP AM_4_MEyahoo.co m> wrote in message
news:uP******** ********@TK2MSF TNGP09.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.te xt = "change, damn your hide!";

which is the same as:
printpage.mainb ut.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_20 122@_hotmail.co m> wrote in message
news:#c******** ******@TK2MSFTN GP15.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.c s. 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_SP AM_4_MEyahoo.co m> wrote in message
news:uP******** ********@TK2MSF TNGP09.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.te xt = "change, damn your hide!";

which is the same as:
printpage.mainb ut.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_20 122@_hotmail.co m> wrote in message
news:#c******** ******@TK2MSFTN GP15.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.c s. 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_SP AM_4_MEyahoo.co m> wrote in message
news:uP****** **********@TK2M SFTNGP09.phx.gb l...
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.c s on page_load event:

show oshow = new show() ;
oshow.PerformHa ndShake(this) ;

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

protected mainform MainFormPointer :

public void PerformHandShak e(mainform mainfptr)
{
this.MainFormPo inter = mainfptr;
}

private void Page_Load(objec t sender, System.EventArg s e)
{
String Main = " Show Me";
string post = this.MainFormPo inter.GetURL(Ma in); --> 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_SP AM_4_MEyahoo.co m> wrote in message
news:eH******** *****@TK2MSFTNG P12.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.te xt = "change, damn your hide!";

which is the same as:
printpage.mainb ut.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_20 122@_hotmail.co m> wrote in message
news:#c******** ******@TK2MSFTN GP15.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.c s. 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_SP AM_4_MEyahoo.co m> wrote in message
news:uP***** ***********@TK2 MSFTNGP09.phx.g bl...

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
2294
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? -- Andrew J. Kelly SQL MVP
2
2091
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 to the datagrid, but because there isn't a custom object with properties, just a string object, I'm not sure how to reference it in the datagrid. FYI, I can enumerate through the collection... foreach(string modelNum in...
4
4085
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 web page from the VS2003 ASP page designer, extracting an XML document from SQL Server during Page_Load, then adding asp:TableRows & asp:TableCells one at a time / loading the corresponding xml values a cell at a time. Is there a better (less...
3
2740
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. After the binding statement, when I check for dataset.getchanges ... it alway returns that there is changes (even the propety just set the value and get the same value to return)... I have tried to understand what has changed by using the...
1
9248
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 DataBinding accepts as a data source either an IList or an IListSource at System.Windows.Forms.ListControl.set_DataSource(Object value)
1
1460
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 textbox is a part of a subform and it shows three times the last value of the record set. Private Sub Form_Open(Cancel As Integer) Dim qry As String, rst As Object qry = "SELECT tbl_EquipmentChronology.Equipment1 FROM tbl_EquipmentChronology...
2
5699
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 control does NOT refresh it's display according to value set to underlying propery while at the same time textBox2 does refresh accordingly. Both textboxes ar located on the same form and there are no diferences in their bindings.
2
3189
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 datasheet view so that they look exactly the same. I just want to know whether it is better to bind the forms record source to the queries or to a sql statement that would include the relevant tables and fields. Please advise thanks
3
18583
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 toolbox called an Option Group. It could contain any number of radio buttons (which Access called Option Buttons), each of which had a "value" property. The Option Group as a whole had a property equal to the value of the selected radio button. Thus...
2
4392
by: Ronald S. Cook | last post by:
Does anyone know why an IEnumerable might not bind to a DataGridView? Thanks, Ron
0
8403
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
8737
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...
1
8509
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
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
7345
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6174
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.