Twister Posted November 8, 2005 Posted November 8, 2005 Hello, I've got a little Prob.: Default.aspx - includes a Label (let's say Label1) CustomClass.vb Now i do Dim CC as new CustomClass CC.test() In CustomClass, in Function test I want access to the Label which is in Default.aspx. How can I do this? I do not want to do something like CC.test(Label1).. Any ideas? Thanks in advance! :) Quote
cyclonebri Posted November 8, 2005 Posted November 8, 2005 What are you trying to do with the label? Set some value from the class? If so, you need to add a public event in your class, and raise the event. You will also need to add an event handler on your default.aspx page, so that when the class raises the event you can have the label respond: in default.aspx, add the following code in your page load method (it needs to load each time, including post-backs: AddHandler YourClassVariable.SetLabelText, AddressOf SetLabelTextFromClass Also on default.aspx add the following method Public Sub SetLabelTextFromClass(byval newtext as string) label1.text = newtext '...whatever else you want to do on the event firing End Sub Inside your class, put the following Public Event SetLabelText(ByVal whatevertext As String) Then from whatever method inside your class that updates the text: '...inside the method RaiseEvent SetLabelText("Text set by class method x") Good Luck. If you need it to do something else, the best way to do so would be events. You could also use delegates but that is more complex and seems to have less functionality. Brian Quote
Twister Posted November 8, 2005 Author Posted November 8, 2005 Hello cyclonebri, thanks for your answer. I thought about a solution like this, but was not able to do it alone, but is there also a possibility to do this without the need to add code to default.aspx? I recently found out, that I can access the session, request, response...etc. object by using httpcontext.current.session in a class. I'm looking for something similiar, like currentpage.findcontrol('Label1').Text = "abc" ?! Thanks, Twister Quote
Administrators PlausiblyDamp Posted November 8, 2005 Administrators Posted November 8, 2005 Is there a reason why you do not want to pass any parameters in? Would you not consider parameterisng the constructor and passing a reference to the page in on creation and storing that within the class for the remaining methods to act upon? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Twister Posted November 8, 2005 Author Posted November 8, 2005 Yes, there is a reason. I use this class in many pages and with this method, i need to add code to each page. Now I want to change something in the SetLabelTextFromClass Sub and I have to do this in all pages... I hoped there would be an easy solution doing this only in the class.... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.