Home All Groups Group Topic Archive Search About
Author
17 Nov 2005 11:01 AM
serge calderara
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
serge

Author
17 Nov 2005 12:15 PM
Harish Ranganathan
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.


Show quoteHide quote
"serge calderara" wrote:

> 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
> serge
Author
17 Nov 2005 2:11 PM
serge calderara
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 ?

Show quoteHide quote
"Harish Ranganathan" wrote:

>
> 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.
>
>
> "serge calderara" wrote:
>
> > 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
> > serge