1

I'm trying to separate my presentation and logic as much as I can, but there's one problem.

How can i set the text-property to a dynamic value from my design file? I want to do like this:

<asp:Textbox id="txtUrl" runat="server" Text="<%= user.URL %>" />

But this will fail. Am i forced to do this from code behind?

3 Answers 3

2
<asp:Textbox id="txtUrl" runat="server" Text="<%# user.URL %>" />

It's all about the #. but it won't get set till txtUrl.DataBind() or something higher in the object heirarchy (like the Page) calls DataBind().

Sign up to request clarification or add additional context in comments.

Comments

1

How about this :

<input type="text" 
  id="txtUrl" name="txtUrl" runat="server" 
  value='<%= user.URL %>' />

Comments

0

You can use binding instead of evaluation.

This code binds a text box's Text property to a user's Url property returned by MyData.GetLoggedInUser(). This allows for 2-way binding.

<asp:FormView ID="UserView" runat="server" DataSourceID="LoggedInUser">
    <ItemTemplate>
        <asp:TextBox ID="tb" 
                     runat="server" 
                     Text='<%# Bind("Url") %>'></asp:TextBox>
    </ItemTemplate>
</asp:FormView>
<asp:ObjectDataSource ID="LoggedInUser" 
                      runat="server" 
                      SelectMethod="GetLoggedInUser" 
                      TypeName="MyData">
</asp:ObjectDataSource>

1 Comment

Well, the output I get is <input name="txtURL" type="text" value="<%= user.URL %>" id="txtURL" />. How would I do the binding solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.