0
votes

I have a web form where I have a Label and a user control. I would like that the user control would be able to change the value of the text in the Label.

How can I indicate to the user control what Label to change? (In the example I have a single Label a a single instance of the user control, but I will need to have several of both)

EDIT:The user interaction with the user control triggers the update of the external label.

EDIT2: Adding more details. My user control has a gridview, when the user adds or edit a line to the grid, I want to update the value in the label with the sum over a column of the grid. Currently I'm using the code server side, as the request to update or insert goes to the server. If possible, I prefer to do the update on the client side, as that would allow me to update my label without having to reload the whole page.

Solution: changed to use devexpress components, I use the aspxgridview client side event EndCallback in the user object. I defined a property in my user object to store the javascript function to be called in the EndCallback callback. This Property can be filled by the container page, as there I know all the IDs I need.

The code I have is:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <uc1:InvoiceItems runat="server" ID="InvoiceItems" />
      <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>
3

3 Answers

0
votes

If you know which label you want to control, you can always have some property in user control, which keeps that label id.

0
votes

You could have a generic method in your control to set values of a label and pass that label control to the function.

The function simply does passedLabel.Text = "My Text"

0
votes

I solved this by doing the changes in the client side. I in my user object I did:

public String ClientCallback { get; set; }
private void Page_Init(object sender, EventArgs e)
    {
      GridView.ClientSideEvents.EndCallback = ClientCallback;
    }

On the page I have:

<dr:UserObject runat="server" ID="UserObject1"
ClientCallback="UpdateFeesTotal" />

The function UpdateFeesTotal is a javascript function that updates the Labels, Now also using a ASPxLabel to use the client side functionality.