Referring to a control on another page

G

Greg Smith

What is the syntax to reference a control on another page? I have a class
module that I would like to code to change parameters on a series of
controls on a web page. There are to many to pass by reference. Is there a
way to do something like



pgMain.cmd1.enabled = true;

pgMain.cmd2.enabled = true;

pgMain.cmd3.enabled = true;

.......



Any help is greatly appreciated.
 
J

John Saunders

Greg Smith said:
What is the syntax to reference a control on another page? I have a class
module that I would like to code to change parameters on a series of
controls on a web page. There are to many to pass by reference. Is there
a way to do something like

If this class (one no longer says "class module") is specifically for this
one page (as it must be since it is meant to touch this large set of
controls), then perhaps it should be part of that page.

Do you see yourself reusing this same class for a different page? If so,
then perhaps the set of controls to be manipulated by this class should be
broken out into their own UserControl, and perhaps the logic from your class
should become part of the UserControl. Are these controls physically
contiguous?

If your class knows details about the page, then you can give it access to
the page by passing "Me" to it:

Public Class WebForm1
Inherits System.Web.UI.Page
Friend WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Friend WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Friend WithEvents TextBox3 As System.Web.UI.WebControls.TextBox

#Region " Web Form Designer Generated Code "
#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim c1 As New Class1()
c1.EnableControls(Me)
End Sub
End Class

Public Class Class1
Public Sub EnableControls(ByVal page As WebForm1)
page.TextBox1.Enabled = True
page.TextBox2.Enabled = True
page.TextBox3.Enabled = True
End Sub
End Class

But notice that Class1 can only be used by one page. In this case, there's
no real sense in creating a class for it - it should be part of the page.

John Saunders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top