Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Values between Controls

Status
Not open for further replies.

ResolutionsNET

IS-IT--Management
Jul 31, 2000
70
GB
Hi,

I need to pass/access varibles from two controls (see below) how do I do this?

<%@ Page Buffer=&quot;true&quot; Language=&quot;VB&quot; Explicit=&quot;true&quot; %>

<%@ Register TagPrefix=&quot;x&quot; TagName=&quot;1&quot; src=&quot;/inc/_1.ascx&quot; %>
<%@ Register TagPrefix=&quot;x&quot; TagName=&quot;2&quot; src=&quot;/inc/_2.ascx&quot; %>

<%@ import Namespace=&quot;System.IO&quot; %>

<x:1 id=&quot;first&quot; runat=&quot;server&quot; />
<x:2 id=&quot;second&quot; runat=&quot;server&quot; />


Thanks
 
Hey Winter,

All you have to do is write some &quot;wrapper&quot; functions in your user control

For instance, lets say that your user control has a textbox called TextBox1. If you wanted your page's codebehind to get that value, you'd write this function in your ascx:

Public Function GetTextBox1Value() as String
GetTextBoxValue = TextBox1.Text
End Function

So in your page, if you wanted that value, you just say:

UserControl.GetTextBoxValue()

Its very similar to the Get/Set idea in object code

hth

D'Arcy
 
If your gunna to get sets then just use the Property structure thingy

Public Property TextBox1Value() As String
Get
TextBox1Value = TextBox1.Text
End Get
Set(ByVal Value As String)
TextBox1.Text = Value
End Set
End Property


This way you can get/set the properties like you would a normal property
something = UserControl.TextBox1Value

UserControl.TextBox1Value = &quot;something&quot;


It is pretty much the same as Jacks with just a little more flexibility in it.
That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Oh sure, the guy passes me in the standings AND critiques my code.

I know its &quot;Anyhoo&quot; jealousy.

;)

Good point about the properties though. It really is six of half a dozen (i think I said that right...my boss always says it anyway): if you want to only read from teh control, either will work, but the property would require more lines of code. If you want to be able to set and read though, Mark's code definately makes more sense.

D'Arcy
 
Thanks guys, this is great stuff. It's already an option I've tried. What I have the problem with, is how do I access properties from x:1 whilst inside x:2.

Any ideas

Cheers
 
well, if all you want to do is get a property and pass it in, then you just set up the code we suggested in both. Then, when you want the value from uc1:textbox1 to go to uc2:textbox1 you would just go

uc1.TextBox1Value = uc2.TextBox1Value

If you need to have the usercontrols access the data in a different way, maybe you need to create another usercontrol that contains both of the usercontrols

D
 
[rofl2]
You are still above me in the overall standings my friend
lol

Anywho
I go back to my dungeon That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
?

Not according to my list; I'm in 3rd, you've got 2nd spot.

(er...not that I'm counting or anything, or focussing on the competitive nature of these forums...oh no)
;)

D
 
no not at all the would be un.... something like
meh
Odd though that we are getting different lists. When I said overall list I had clicked on the Full List link at the bottom of the page link. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Well I'll be...didn't even know that full list existed.

Mine must just be funky then, as Netangel is ahead of Alcar on mine.

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top