Basics of Custom Controls and Namespaces (CS0103) RRS feed

  • Question

  • User1858242605 posted

    I am creating a custom control to display an image based on a database field. If field=1, show image1, if field=2, show image2, etc.

    The following error appears..."CS0103: The name 'SetPercentageCompleteImage' does not exist in the current context". It seems to me that the default.aspx page cannot see the SetPercentageComplete function in PercentComplete.ascx.cs so I think it is namespace problem. I have tried to configure a namespace but this just generated more errors.

    The key elements of the user control and default page are listed below:


    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="PercentageCompleteImage.ascx.cs" Inherits="PercentageCompleteImage" %>

    <asp:Image ID="Image1" runat="server" ImageUrl="~/0_Perc_Comp.png" OnLoad="SetPercentageCompleteImage" />



    using System;

    using System.Collections;

    using System.Configuration;

    using System.Data;

    using System.Linq;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.HtmlControls;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Xml.Linq;

    public partial class PercentageCompleteImage : System.Web.UI.UserControl


    protected void Page_Load(object sender, EventArgs e)            {        }

    public String PerCentValue

               { getset ;  }public void SetPercentageCompleteImage(object sender, EventArgs e)


    int x = Convert.ToInt32(PerCentValue);

    switch (x) {

    case 0: Image1.ImageUrl = "~/0_Perc_Comp.png"; return;

    case 1: Image1.ImageUrl = "~/10_Perc_Comp.png"; return;

    case 2: Image1.ImageUrl = "~/20_Perc_Comp.png"; return;

    case 3: Image1.ImageUrl = "~/30_Perc_Comp.png"; return;

    }  }  }


    Elements of Default.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <%@ Register src="PercentageCompleteImage.ascx" tagprefix="uc1" tagname="PercentageCompleteImage" %>

    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>   .....using this for the RADGrid with control in a template



    The template where the problem occurs. 

    <telerik:GridTemplateColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" ForceExtractValue="None" UniqueName="column" HeaderText="Status">

        <EditItemTemplate>      <asp:TextBox runat="server"></asp:TextBox>    </EditItemTemplate>

        <ItemTemplate> <uc1:PercentageCompleteImage  ID="PercentageCompleteImage1" runat="server" PerCentValue='<%# SetPercentageCompleteImage(Eval("Status")) %>' />  </ItemTemplate>   .....this is the problem line (referencing the Status field which is a GridBoundColumn further up the page).


    Thanks in advance


    Friday, May 9, 2008 4:05 AM


  • User1858242605 posted

    Managed to remove this error  message by changing the <Item Template>

     PerCentValue='<%# SetPercentageCompleteImage(Eval("Status")) %>'


    PerCentValue='<%# DataBinder.Eval(Container, "DataItem.Status") %>' which is the correct approach.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 13, 2008 8:22 AM