Results 1 to 2 of 2

Thread: Controls on other ascx

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Location
    Left past the postbox
    Posts
    30

    Controls on other ascx

    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

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    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
    VB Code:
    1. <script language="vb" runat="server">
    2. Public Property TurkeyName() As String
    3.     Get
    4.         Return  _TurkeyName.Text
    5.     End Get
    6.     Set(ByVal Value As String)
    7.         _TurkeyName.Text = Value
    8.     End Set
    9. End Property
    10. Public Property EatStuffing() As Boolean
    11.     Get
    12.         Return _EatStuffing.Checked
    13.     End Get
    14.     Set(ByVal Value As Boolean)
    15.         _EatStuffing.Checked = Value
    16.     End Set
    17. End Property
    18. </script>
    19. <asp:TextBox
    20.     ID="_TurkeyName"
    21.     Runat="server"/><br />
    22. <asp:CheckBox
    23.     ID="_EatStuffing"
    24.     Text="Do you eat stuffing?"
    25.     Runat="server"/>

    MyTestPage.aspx
    VB Code:
    1. <%@ Register Tagprefix="Thanksgiving" Tagname="Turkey" Src="MyUserControl.ascx" %>
    2. <script language="vb" runat="server">
    3. Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    4.     MyTurkeyDayControl.TurkeyName = "Chris"
    5.     MyTurkeyDayControl.EatStuffing = True
    6. End Sub
    7. </script>
    8. <html>
    9.   <head>
    10.     <title>MyTestPage</title>
    11.   </head>
    12.   <body>
    13.  
    14.     <form id="Form1" method="post" runat="server">
    15.         <Thanksgiving:Turkey
    16.             Runat="server"
    17.             ID="MyTurkeyDayControl"/>
    18.     </form>
    19.  
    20.   </body>
    21. </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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width