Question

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.

Was it helpful?

Solution

<%# 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top