Pass variable to UserControl
I try to pass Package
variable to my UserControl:
<uc:Template ID="Template" runat="server" Package="<%=TemplateParams.SimpleSearch %>" />
but with no luck - in UC it gives me <%=TemplateParams.SimpleSearch %>
string instead of SimpleSearch
parameter from TemplateParams
class.
How to do this ?
Edit:
About code behind way I know - I wou开发者_如何转开发ld like to know how to do it from view.
In the user control that holds the property you're attempting to expose you can set the BrowsableAttribute
attribute:
[BrowsableAttribute(true)]
public string myProperty { get; set; }
This should expose it in the xml version of the control.
Edit
If your TemplateParams.SimpleSearch
is a string, then you should be able to do the following:
Package='<%=TemplateParams.SimpleSearch%>'
The '
makes the difference here. If it is an object, you'll have to do it in the code behind.
From code behind you can pass variable or set properties
Template.variable="foo";
Page.FindControl("Template").Attributes.Add("Package", "YourValueGoesHere");
An alternative, if you really want to do it in the markup is to use an expression builder
we use this one for lots of similar tasks
This will allow you to write code like
<uc:Template ID="Template" runat="server" Package="<%$ Code : TemplateParams.SimpleSearch %>" />
精彩评论