开发者

Using code nuggets for setting controls properties

Why cant i use code nuggets to set a control property??For example a vali开发者_开发百科dationgroup of a button or the text property of a label.

<asp:Button ID="btn" runat="server" Text="test" ValidationGroup='<% =TestValidate %>'

<asp:Label ID="lbl" runat="server" Text='<% =Test %>' />

Is there any way to set a controls properties without using codebehind?


You could use data binding:

<asp:Label ID="lbl" runat="server" Text='<%# "Hello World" %>' />

provided that you call DataBind in code behind:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DataBind();
    }
}


<%=SomeVar %> uses late binding which behaves like a Response.Write (in Page.PreRender, if I remember correctly). Hence it will not be utilized by the server controls like the way you wanted it. Unless you use code-behind or inline-code-behind to perform binding.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜