开发者

How to assign class static variables to control in aspx page?

I have one static class with two property.

public class SiteDetails
{
    public static string MetaIndexKeyword { get; set; }
    public static string SiteName { get; set; }

}

And one default page where i need to assign these static value on page load.

<meta name="keywords" content='<%= DealCollector.Model.SiteDetails.MetaIndexKeyword %>' />
 <asp:Label id="test" runat="s开发者_如何学Pythonerver" Text='<%= DealCollector.Model.SiteDetails.HtmlMetaKeyword %>'></asp:Label> 

And Static class and Default page Namespaces are different.

When I am calling simply like this

<%= DealCollector.Model.SiteDetails.HtmlMetaKeyword %>

Then it working fine but in control and meta value it's not showing value.

please help me to find this solution.


<%= expressions cannot be used as properties, you have to use <%# expressions instead.

Since <%# expressions are evaluated at DataBind() time, if you used that, then you need to call DataBind(); method at PreRenderComplete like..

protected void Page_PreRenderComplete(object sender, EventArgs e)
{
    DataBind();
}

Finally it will be like, if you set the property to your label control

Text='<%# DealCollector.Model.SiteDetails.HtmlMetaKeyword %>'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜