Reputation: 1265
Hi guys i'am having problem using a property in <%= %> tags. The compiler for some reason would not pick up the properties inside the <%= %> tags. IDE being used is MVWD The error i get is
Error 2 'ASP.webusercontrol1_ascx' does not contain a definition for
'UserName' and no extension method 'UserName' accepting a first argument of type
'ASP.webusercontrol1_ascx' could be found (are you missing a using directive or an
assembly reference?) c:\Users\jonny\Documents\Visual Studio 2010\Projects\WebApplication8\WebApplication8\WebUserControl1.ascx 2 36 WebApplication8
My WebUserControl1.ascx file
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs"
Inherits="WebApplication8.WebUserControl1" %>
<b>Information about </b> <%= this.UserName%>
<br /><br />
<%= this.UserName %> is <%= this.UserAge %> years old and lives in <%= this.UserCountry %>
and here is my Webusercontrol1.ascx.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication8
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
private string userName;
private int userAge;
private string userCountry;
public string UserName
{
get { return userName; }
set { userName = value; }
}
public int UserAge
{
get { return userAge; }
set { userAge = value; }
}
public string UserCountry
{
get { return userCountry; }
set { userCountry = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
Upvotes: 1
Views: 186
Reputation: 1128
I think you can put the fields into literal controls, it's true the aspx will look ugly. something like this (I'm using for resources but should be simillar)
<asp:Literal ID="Literal6" runat="server" Text="<%$ Resources:General, lblFunctie %>"></asp:Literal>
Upvotes: 1