Groups | Blog | Home
all groups > asp.net webcontrols > november 2005 >

asp.net webcontrols : Simple question ???


serge calderara
11/17/2005 3:01:02 AM
Dear all,

I have build a simple Web user control which contains 2 labels named Lab1
and Lab2.

I defined property for that control to change the .Text property of both ogf
them.
Then I drag my user control on an empty form whcih contains only my created
user control.

Then I set the text property of those control through my Web form code as :

dim myControl as new USerContrl
myControl.SetText ="Test value"

This code is place in my webForm Page_PreRender, but when it runs my user
control labels text property has not change, it contain default value.

What I am doing wrong ?
Is it the properway to do or should I use a Control Libary ?

Thanks for your help
regards
Harish Ranganathan
11/17/2005 4:15:05 AM

Hi,

Try placing the same code in the Page_Load event. It should work fine.
Alternatively you can also set the property in the Usercontrol declaration in
your aspx page.

Write back if this doesnt help.

Thanks.


[quoted text, click to view]
serge calderara
11/17/2005 6:11:08 AM
Hi, it does not help

Once agin to be sure you understand :
I have created a simple user control which contains only a simple label
server control as MyLabel.

In my user control code I have a property as follow:

Public Property LineName() As String
Get
'Return m_sLineName
Return ViewState("Line")
End Get
Set(ByVal Value As String)
ViewState("Line") = Value
End Set
End Property

Then I drag my control on an empty webForm. SO by dragging I can see only a
generic control graphic (not my label)

Then what I am trying to do is display MyLabel.Text property on my WebFrom
according to the property value I have set.
Then on my WebForm code load event I have the following :

dim ctlReel = New myControl
ctlReel.LineName = "Test"

When executing, my WebForm lable control as the value of "label" instead of
Test

It is clear that if I add on my WebForm a new lable and populate its value
like:

myWeFrom.NewLable.Text= ctReel.LineName

Then I get displayed the "Test" string previously set
But this is not what I want, I would like that when my page display, it show
myUserControl value previously set

What is wrong ?

[quoted text, click to view]
AddThis Social Bookmark Button