3

Greetings,

I have a control and list of variables and I want in the control property to be assigned to the variable value directly in the page not from the back code, something like this

My global variables

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

in my custom control instead of:

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

To this

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

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

Thanks

Kronass
  • 5,266
  • 3
  • 19
  • 25
  • You title is clear, but the question itself isn't. How is what you have written related to the title? What exactly is your question? Why are resource files mentioned? Do you need to internationalize? – Oded Aug 31 '10 at 08:22
  • @Oded: I put the global variable as const in this example and I mentioned resource file as one of workarounds to solve this problem (wrong way to solve but it does solves it). what is the part of question is vague so I can update it. thx – Kronass Aug 31 '10 at 08:37
  • @Oded: I updated my question if this makes it more clear – Kronass Aug 31 '10 at 08:50

3 Answers3

5

You can do it like this 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 in order for the databinding expression to be evaulated.

But if you are going to do this then you might as well assign the property in the page load.

Chris Mullins
  • 6,677
  • 2
  • 31
  • 40
0

I think you should go with a property (protected should be enought, but I'll say public in the following snippet) in your code behind:

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

Then you can use it in your controls, for example:

<uc:LoadPie id="pieBanana" type="<%= myBanana%>" />
themarcuz
  • 2,573
  • 6
  • 36
  • 53
  • In your code it will not send the property value as a value, it will send "<%= myBanana%>" string as a value to the type – Kronass Aug 31 '10 at 08:45
0

Not quite what you want, but how about:

<% pieBanana["type"] = this.Banana %>
Jerome
  • 1,162
  • 1
  • 6
  • 12