views:

29

answers:

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

A: 

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
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
Yes, my fault. Chris Mullins's answare is the right one
themarcuz
A: 

Not quite what you want, but how about:

<% pieBanana["type"] = this.Banana %>
Jerome
+2  A: 

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
@Chris Mullins: you are right.That's the way to go. Just a little typing error:type='<%# Banana %>'
themarcuz
thanks for letting me know about the typo I fixed it.
Chris Mullins