How to assign control property value from global variable to page code?

Hi,

I have a control and a list of variables, and I want the control to assign a value to the variable directly on the page, and not from the reverse code, something like this

My global variables

public string Banana = "banana_pie";
public string Apple = "apple_pie";

in my user control instead:

<uc:LoadPie id="pieBanana" type="banana_pie" />

For this

<uc:LoadPie id="pieBanana" type="<%=Banana %>" />

so there is a way or just assign a property in the reverse code of the page.

thank

+3
source share
3 answers

You can do it this way using data binding syntax.

<uc:LoadPie id="pieBanana" type='<%#Banana%>' runat="server"></uc:LoadPie>

But then in your code behind you have to call

pieBanana.DataBind();

in the page load so that the data binding expression is evaluated.

, .

+5

, ( , ) :

Public Property myBanana() As String
   Get
      Return Pies.Banana;
   End Get
End Property

, :

<uc:LoadPie id="pieBanana" type="<%= myBanana%>" />
0

, , :

<% pieBanana["type"] = this.Banana %>
0

Source: https://habr.com/ru/post/1762418/


All Articles