문제

when I'm doing this, it works just fine:

submitBtt.Text = "test";

in the page load function.

but, when I'm trying to use it like this:

<asp:Button ID="submitBtt" OnClick="submitBtt_Click" runat="server" Text=' <%# test() %>'  Width="80px" />

the test function is in the code behind:

public string test()
    {
        return "test";
    }

all i get is a button with no text.

tried to Google it a lot and couldn't find any answer.

Thanks in advance.

도움이 되었습니까?

해결책

<%# is for databinding context only. So you need to call DataBind on the NamingContainer of this control. In this case the page itself:

For example in Page_Load:

this.DataBind();

Here's a quick overview over the inline asp.net tags.

I would prefer using codebehind without the inline aspx since that's confusing and also hard-wiring the view with the business logic.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top