 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 10th, 2003, 11:40 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Get user control to refresh
I have a user control template that I am using on every page. The control displays a system message that is pulled from a database. One of the pages in my site enabes users to change the message displayed on the user control. When I use a handler to submit the page the old message shows in the user control because I assume it did not get refreshed. How can I refresh the message in the user control?
|
|

November 10th, 2003, 01:41 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
What's happening is that your usercontrol is loading up (with the old message), then your handler on the page is setting the message to the new value the user entered. You need to create a publicly accessible method on the user control that you can call from the update button's event handler in the update page code. This method should make another call to the code that gets the message.
This is fairly simple if you are including the user control on the ASPX page.
In the end your ASCX code should include something like this:
Private Sub Page_Load(...)
GetMessage()
End Sub
Public Sub GetMessage()
'Here's where you'll call the DB to get the message
End Sub
And here's what your ASPX code will include:
Private Sub cmdMyButton_Click(...) Handles cmdMyButton.Click
ucMyMessageUserControl.GetMessage()
End Sub
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

November 10th, 2003, 02:52 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Peter,
I did that but in my user control I am using a label to show the contents of the message. Since the lablel is not a public variable I am getting a page error on the aspx that says "Object reference not set to an instance of an object. " in reference to Me.lblPrivateMessage.Text. How should I change my sub GetMessage so that the lbl is no longer a private object?
This is the sub in my ascx page:
Public Sub GetMessage()
'Run oledbreader to get message.
Me.lblPrivateMessage.Text = 'value from db
End Sub
This is the sub on my aspx page:
Private Sub cmdMyButton_Click(...) Handles cmdMyButton.Click
ucMyMessageUserControl.GetMessage()
End Sub
|
|

November 10th, 2003, 03:05 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
You need to make that label a object in the page code. In visual studio, this happens automatically. Try this...
Protected lblPrivateMessage As System.Web.UI.WebControls.Label
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

November 10th, 2003, 03:24 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I put that line on my right under the class declaration on my aspx page but I am still getting errors. Could you be more specific.
Thanks a lot!
Anne
Quote:
quote:Originally posted by planoie
You need to make that label a object in the page code. In visual studio, this happens automatically. Try this...
Protected lblPrivateMessage As System.Web.UI.WebControls.Label
Peter
------------------------------------------------------
Work smarter, not harder.
|
|
|

November 10th, 2003, 03:33 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
I can't really get more specific than that.
What are you developing in? VS.Net?
What's the error you are getting? Still the same error?
If all else fails, paste your code here so we can look it over.
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

November 10th, 2003, 03:46 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here is the code. I am stil getting the error "Object reference not set to an instance of an object." in regards to lablemessage.text because it is a protected variable on the user control. I hope this explains it better.
The sub on the ASCX page. The sub GetSystemMessage() inherits another class called clsSystemMessage to do all the database stuff. The object should return the text from the db:
--------------------------------------------------------
Public Class UCTop_Secure
Private Sub Page_Load(...)
GetSystemMessage()
End sub
Public Sub GetSystemMessage()
Dim objSystemMessage As New clsSystemMessage
objSystemMessage.ShowSystemMessage("A")
labelMessage.Text = objSystemMessage.SystemMessage
'labelMessage is an html label placed on the ascx design
End Sub
End Class
Here is the sub on the ASPX page.
-------------------------------------------
Private Sub cmdSendNote_Click(..) Handles cmdSendNote.Click
UpdateSystemMessage()
Dim objUCTop_Secure As New UCTop_Secure
objUCTop_Secure.GetSystemMessage()
End Sub
|
|

November 10th, 2003, 04:07 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The error that I mentioned in the previous post only happens when the Sub cmdEmail_Click handler is run. This sub is trying to access the user control class and it is failing because it cannot access the labelmessage protected variable.
Anne
|
|

November 10th, 2003, 04:21 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Public Class UCTop_Secure
Protected lblPrivateMessage As System.Web.UI.WebControls.Label
Private Sub Page_Load(...)
...
That should do it. Perhaps I mislead you earlier. I meant to say that the label needed to be in user control code (not page code).
And just a small note on terminology:
"The sub GetSystemMessage() inherits another class " is not quite right. That sub is just using an instance of another class, not inheriting it. Only classes and interfaces can inherit (to the best of my knowledge).
Peter
------------------------------------------------------
Work smarter, not harder.
|
|
 |