Accessing objects from other classes in ASP.NET (VB)
Please forgive the newb question. I am very new to .NET so don't assume I've done something basic.
In ASP.NET I have a form that has a Textbox named txtOutput and a button. In the main file.aspx.vb I can call a function from the button handler and in that function I can have
txtOutput.Text = "Some Message"
with no problem. I have a bunch of functions in several other classes. For instance I have a class named AbleCommerce that does some database functions. These functions are called from my main class. In those functions, however, I have no visibility of txtOutput. All of my classes are, unfortunately, in the default namespace which I understand is not optimal but didn't seem to impact this issue.
I know this is an easy one I've just not understood properly but it has me stumped. My gut says that I probably ne开发者_高级运维ed to pass the Textbox object to my "other class" but can't for the life of me figure how.
Any help is appreciated. Thanks!
The normal way is something like this:
MyTextBox.Text = MyDBClass.GetName(userID)
That is, you have classes that don't know about the UI, and a codebehind that takes values from the classes and assigns them to UI widgets.
Instead of passing ASP.NET server controls to your DAL classes pass only the values they need like for example the text that has been entered in a textbox:
Dim username As String = edtUser.Text
Dim c As New AbleCommerce()
c.SomeFunction(username)
精彩评论