Help with use of class file....

G

Guest

I need some help understanding how I can create a function in a class file
that is available to every page on my site and that can interact with a
placeholder control that is already on the page. Below is a code sameple that
doesn't work, could someone point me in the right direction?

---from Global_Class.vb

Public Class Global_Class

Public Sub add_control_test(byref placeholder as
system.ui.webcontrols.placeholder)

dim new_text_box as System.web.ui.webcontrols.textbox
new_text_box.text="test"

placeholder.controls.add(new_text_box)

End Class


---from default.aspx
<body blah blah>

<asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>

</html> yada yadda


---from default.aspx.vb

Public Class _default
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

Dim global_class As New <website>.Global_Class

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

global_class.add_control_test(PlaceHolder1)


End Sub

End Class


Any help would be greatly appreciated!

TIA,
Blax...
 
K

Karl

Blaxer, it looks fine. What doesn't work about it? An error or the textbox
just doesn't show up?

Two notes, you don't have to pass the placeholder byref...byval is fine, but
that won't change anything

and declare you sub as shared ala public shared sub add_.....
then you can get rid of the Dim global_class As New <website>.Global_Class
and just call <website>.Global_Class.add_... without an instance of the
class..but again I that won't change anything.

Karl
 
G

Guest

Hmmm, it doesn't seem to work at all, it complains about needing a child
object for the placeholder inside the class file... ??

Blax...
 
K

Karl

Oppss..one thing i just noticed is that you never actually create a new
textbox:
dim new_text_box as System.web.ui.webcontrols.textbox
should be
dim new_text_box as NEW System.web.ui.webcontrols.textbox

your naming convention makes things like that hard to spot..

karl
 

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

Top