I have the following setup in my application and I’m having some difficulties passing values my user control.
ASPX
<%
var posts = this.getPosts();
foreach (var post in posts)
{ %>
<asp:TextBox runat="server" Text="<%: post.post_id %>" />
<% } %>
CS
DataClassesDataContext db = new DataClassesDataContext();
public Post[] getPosts(int offset = 0, int lenght = 10)
{
var resultSet = db.Posts.OrderBy(x => x.date).Skip(offset).Take(lenght).ToArray();
return resultSet;
}
protected void Page_Load(object sender, EventArgs e)
{
DataBind();
}
The TextBox value on page load is “<% post.post_id %>”. I even tried using the <%# post.post_id %> tag but that gives an error – “The name ‘post’ does not exist in the current context”.
Any suggestions?
I would suggest moving to a repeater control instead of using in-line C# in your markup code. Alternatively, you might try using Eval (although, not sure it would apply here):