PDA

Click to See Complete Forum and Search --> : Controls on other ascx


ChrisWise
Nov 27th, 2002, 06:41 AM
How can I retrieve the value of a textbox or set the value of a check box on a different ascx, Ive been trying:

previous is the name of the file (previous.ascx)

Previous.txtName.text = txtuser.text


And how do I declare a global variable that can be accessed from all of my project, I have declared it in the global.asax but I still cant declare it.

PLS HELP!!!!!!!!

Thanks

Chris

pvb
Nov 27th, 2002, 11:26 AM
Well, in answer to the first part, here's an example(and keep in mind there are a few ways of doin this, this is just one way).
MyUserControl.ascx

<script language="vb" runat="server">
Public Property TurkeyName() As String
Get
Return _TurkeyName.Text
End Get
Set(ByVal Value As String)
_TurkeyName.Text = Value
End Set
End Property
Public Property EatStuffing() As Boolean
Get
Return _EatStuffing.Checked
End Get
Set(ByVal Value As Boolean)
_EatStuffing.Checked = Value
End Set
End Property
</script>
<asp:TextBox
ID="_TurkeyName"
Runat="server"/><br />
<asp:CheckBox
ID="_EatStuffing"
Text="Do you eat stuffing?"
Runat="server"/>


MyTestPage.aspx

<%@ Register Tagprefix="Thanksgiving" Tagname="Turkey" Src="MyUserControl.ascx" %>
<script language="vb" runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
MyTurkeyDayControl.TurkeyName = "Chris"
MyTurkeyDayControl.EatStuffing = True
End Sub
</script>
<html>
<head>
<title>MyTestPage</title>
</head>
<body>

<form id="Form1" method="post" runat="server">
<Thanksgiving:Turkey
Runat="server"
ID="MyTurkeyDayControl"/>
</form>

</body>
</html>


As far as a global variable, the the Application object still exists, so maybe try that. Where appropriate I also use the appSettings section of the web.config file.