0

Hello :)

i've created a user control that contains a label and button.
then i created a web page ... i put the User control in this page
how i could change the label text from the page?
i think i have to create a method? how and where i should create it.?
Thanks in advance!

Edited by JorgeM: Moved to ASP.NET; this is not ASP.

2
Contributors
4
Replies
29
Views
3 Years
Discussion Span
Last Post by Wael1988
0

In the code-behind for the .ascx (page were control exists) page, expose the property

VB Example...

Public Property lblControl As String
   Get
      Return lable1.Text.ToString
   End Get
End Property

C# Example...

public string lblControl 
{
    get 
    { 
        return label1.Text.ToString(); 
    }
}

Then, on your web page in the aspx page, you have to register the control and place the control on the page.

<%@ Register TagPrefix="uc" TagName="ctrl" Src="~/App_Controls/WebUserControl.ascx" %>

<uc:ctrl ID="ucCtrl" runat="server"  />

Then in the page's code behind...

VB

Dim test as String = ucCtrl.lblControl

C#

string test = ucCtrl.lblControl;
0

@JorgeM Thanks alot for your help and i have created Property then i take an object in my page load ..

    string test = ucCtrl.lblControl;

the question is.. how i could give the label a text after this step then?

Edited by Wael1988

0

Sorry, i guess i didnt read your question thorougly... I though you just wanted to get the value of the label control. if you also want to set the value, then modify the code-behind of the .ascx page, and add the set method. Just assign the label control's text property to the keyword value.

assuming C#

public string lblControl
{
     get
     {
          return Label1.Text.ToString();
     }

     set
     {
          Label1.Text = value;
     }
}

Then in your page's code behind...

ucCtrl.lblControl = "new value";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.