473,387 Members | 3,750 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,387 software developers and data experts.

really stuck on passing public variables between controls

I'm really stuck on the concept of using public variables to pass
information between usercontrols. I'm pretty sure I'm just flubbing up the
syntax.

This is what I want:

page
usercontrol 1 - set variable
usercontrol 2 - read variable

I haven't been able to find a tutorial that addresses this issue. It has
been suggested that I use pulic variables, however.

Unfortunately, I'm stumped on the syntax.

I have this in usercontrol 1:

public globadlPageID as String = "2"
But I'm not sure how to access that from Usercontrol 2. Is there a way to
grab something from another control?

-Darrel
Nov 18 '05 #1
4 1591
You have to go through their common element - the page:

Say your page is something like:

<uc1:control1 id="firstControl" runat="Server" />
<uc3:control2 id="secondControl" runat="Server" />

and your codebehind:

public class WebForm1
inherits System.Web.UI.Page

public firstControl as Control1
public secondControl as Control2

sub page_load
...
end sub
end class

you can access the "globalPageId" in firstControl from secondControl via
(this is secondControl):
sub page_load
dim pageId as string = ctype(Page, WebForm1).firstControl.globalPageId
end sub
that's it. Now, you might wanna make sure that Page is of type WebForm1 -
since user controls are meant to be used on multiple pages...but that's the
general idea...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Darrel" <no*****@nospam.com> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
I'm really stuck on the concept of using public variables to pass
information between usercontrols. I'm pretty sure I'm just flubbing up the
syntax.

This is what I want:

page
usercontrol 1 - set variable
usercontrol 2 - read variable

I haven't been able to find a tutorial that addresses this issue. It has
been suggested that I use pulic variables, however.

Unfortunately, I'm stumped on the syntax.

I have this in usercontrol 1:

public globadlPageID as String = "2"
But I'm not sure how to access that from Usercontrol 2. Is there a way to
grab something from another control?

-Darrel

Nov 18 '05 #2
Karl:

THANK YOU! That saved me quite the headache. OK, I think that makes sense. I
can get it to work, but I don't quite get the cast statement. I'm casting
the parent page as my usercontrol? I'm not quite clear on how that logic
works.

Again, THANKS!

-Darrel
Nov 18 '05 #3
No,

ctype(Page, WebForm1)

you are casting Page (which is of type System.Web.UI.Page) to the specific
page instance, WebForm1. System.Web.UI.Page doesn't expose a "firstControl"
property, but WebForm1 does..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:uX**************@TK2MSFTNGP11.phx.gbl...
You have to go through their common element - the page:

Say your page is something like:

<uc1:control1 id="firstControl" runat="Server" />
<uc3:control2 id="secondControl" runat="Server" />

and your codebehind:

public class WebForm1
inherits System.Web.UI.Page

public firstControl as Control1
public secondControl as Control2

sub page_load
...
end sub
end class

you can access the "globalPageId" in firstControl from secondControl via
(this is secondControl):
sub page_load
dim pageId as string = ctype(Page, WebForm1).firstControl.globalPageId
end sub
that's it. Now, you might wanna make sure that Page is of type WebForm1 -
since user controls are meant to be used on multiple pages...but that's the general idea...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Darrel" <no*****@nospam.com> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
I'm really stuck on the concept of using public variables to pass
information between usercontrols. I'm pretty sure I'm just flubbing up the syntax.

This is what I want:

page
usercontrol 1 - set variable
usercontrol 2 - read variable

I haven't been able to find a tutorial that addresses this issue. It has
been suggested that I use pulic variables, however.

Unfortunately, I'm stumped on the syntax.

I have this in usercontrol 1:

public globadlPageID as String = "2"
But I'm not sure how to access that from Usercontrol 2. Is there a way to grab something from another control?

-Darrel


Nov 18 '05 #4
No,

ctype(Page, WebForm1)

you are casting Page (which is of type System.Web.UI.Page) to the specific
page instance, WebForm1. System.Web.UI.Page doesn't expose a
"firstControl"
property, but WebForm1 does..


Thanks, Karl. That really helps clear things up for me!

-Darrel
Nov 18 '05 #5

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

Similar topics

1
by: Prosonman | last post by:
Hi, What is the best way to transfer variables to and from a dialog box? My project consists of a form with a number of controls, lets say three Labels, when a label is clicked it opens a dialog...
3
by: SV | last post by:
Dear all, In my application I have a lot of hidden fields. I want to make them invisible for the users though for debugging reasons I want to make them visible. So I want to add these objects to...
10
by: Steve | last post by:
Can anyone recommend the best way to pass a string back to the calling class (windows form) from a dialog that was shown modally using ShowDialog?
11
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
6
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
0
by: Neelima Godugu | last post by:
Hi All, I have developed a windows forms user control, which I am going to host in Internet Explorer.. I am familiar with the security settings requirement inorder to do the above. I have...
2
by: darrel | last post by:
Is there a SOP for setting variables on an ASPX page that the usercontrols on that page can read? I'd like to set a 'template=' variable that various other controls can see (the header,...
6
by: RBCC | last post by:
Public Class fraction Dim m_numerator As Int16 Dim m_denominator As Int16 Public Event zerodenom() Public Property numerator() As Int16 Get Return m_numerator
10
by: Cliff | last post by:
Greetings, I have been trying to teach myself C++ over the past few weeks and have finally came across a problem I could not fix. I made a simple program that prints out a square or rectangle...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.