By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,694 Members | 1,847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,694 IT Pros & Developers. It's quick & easy.

really stuck on passing public variables between controls

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.