Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Out of Control

Author  Topic 

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2006-05-10 : 10:56:35
I have created a user Control and dragged it onto my page. This works fine. I then created some public properties (methods) for my control (lets call it uc1). My problem is that I cannot access the methods of the control and I'm not sure why. If I put in me. or page. into VS, nothing that looks appropriate shows up in Intellisense. Don't think it matters much but I am using VB.NET for the ASP

Does anyone have any clues about where I start to look to resolve this?

thanks

steve

-----------

Oh, so they have internet on computers now!

dfiala
Posting Yak Master

116 Posts

Posted - 2006-05-10 : 11:13:48
Working in 1.1?

You need to declare the control in your code behind,

Private WithEvents uc1 as MyControl

if you want to reference its properties.

2.0 is little more perceptive on picking up the controls itself (due to partial classes) from the aspx, but in 1.1 and hence 2003, you need to explicitly declare the control.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-05-10 : 18:04:28
Also, in 1.1 you don't get intellisense when designing the HTML for custom controls, only in the code view. Just because the intellisense isn't there in HTML view, doesn't mean that those properties don't exist.
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2006-05-10 : 19:15:25
That's why I like to add my controls on the server side, so I can get all of my Intellisense. Then I just do a "controls.add" to a panel or another container that my controls needs to be displayed in.

Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>

Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2006-05-11 : 03:21:38
Many thanks guys I'll take a look at what you have suggested. On re-reading I realise how poorly I explained what I was doing but you are right I am using 1.1

steve

-----------

Oh, so they have internet on computers now!
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2006-05-11 : 05:12:44
Many Many thanks guys I have now cracked it - I was just being really thick - I blame the heat

steve

-----------

Oh, so they have internet on computers now!
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2006-05-12 : 10:13:40
OK, it's not hot now - in fact there is thunder and lightning outside! but I am still a bit confused.

My app is ASP.NET (1.1) using VB.NET

I have created a User Control with a label on it, the idea being that the page that the User Control is on can change the text in the label.

In the code behind (thanks to you guys) I can now reference the User Control but I can't seem to make any changes to the text of the label i.e. when I try it just doesn't work. I'm sure i have missed something really simple. I have examples which appear almost identical to what I am doing

Here is the code

The User Control is called FixedHeader and the code behind is this

Imports System


Public Class FixedHeader
Inherits System.Web.UI.UserControl

Private sWelcome As String

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

If Not IsPostBack Then 'i.e. set the default values
Welcome = "Hello Stranger"
ELSE
Me.lblGreeting.Text = Welcome
end if
End Sub

' methods for the fixed header object
Public Property Welcome() As String
Get
Return sWelcome
End Get
Set(ByVal Value As String)
If Len(Value) > 50 Then
Value = Left(Value, 50) ' this is enough
End If
sWelcome = Value
End Set
End Property

End Class


The idea of the code above is that the Welcome method alters that text in the label of the User control

In the page where this control is used I have this code behind

 Protected uc1 As New FixedHeader ' This means that the properties of the header user control can be accessed at least in theory

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
If Not IsPostBack Then
...
End If
Me.uc1.Welcome = "Hello You"
End Sub


What happens is that on postback the labels go blank i.e to the values that they are originally declared as in the code behind.

I'm sure I am missing something simple but have no idea where or what. None of the various things I have tried have made much difference.

Thanks in advance

steve

-----------

Oh, so they have internet on computers now!
Go to Top of Page

dfiala
Posting Yak Master

116 Posts

Posted - 2006-05-12 : 10:59:21
State is a little tricky in ASP.NET pages and user controls. The control loads before the property is set, so your page_load code does nothing. Kill it and try this instead...

Public Property Welcome() As String
Get
Return Me.lblGreeting.Text
End Get
Set(ByVal Value As String)
If Len(Value) > 50 Then
Value = Left(Value, 50) ' this is enough
End If
Me.lblGreeting.Text = Value
End Set
End Property

Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw.com/blogbaby
Microsoft MVP
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2006-05-12 : 11:02:11
I'll take a look at that, many thanks Dean

steve

-----------

Oh, so they have internet on computers now!
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2006-05-12 : 11:07:49
That seems to have cracked it - many thanks

steve

-----------

Oh, so they have internet on computers now!
Go to Top of Page
   

- Advertisement -