Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 634811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:20:10+00:00 2026-05-13T20:20:10+00:00

I designed a user control. It contains a public property CurrentValue. When I try

  • 0

I designed a user control. It contains a public property “CurrentValue”.
When I try to initialize the property using an Eval expression, a null value is assigned.

// In below code, label assignment is OK, RatingNull user control assignment get null

<asp:TemplateField>
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Difficulty") %>'
        <uc1:RatingNull ID="RatingNull1" runat="server" CurrentValue='<%# Eval("Difficulty") %>' />
    </ItemTemplate>

If I directly assigned a value (ie, CurrentValue=”5″), user control works fine.

public partial class RatingNull : System.Web.UI.UserControl
{
    private string _CurrentValue;

    public string CurrentValue
    {
        get { return _CurrentValue; }
        set { _CurrentValue = value; }
    }
    (...)
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:20:10+00:00Added an answer on May 13, 2026 at 8:20 pm

    The following code works for me. When do you use _CurrentValue field?

    UserControl

    public partial class Test1 : System.Web.UI.UserControl
    {
    
        public string CurrentValue
        {
            get { return (string)ViewState["CurrentValue"] ?? string.Empty; }
            set { ViewState["CurrentValue"] = value; }
        }
    
        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
    
            writer.Write(this.CurrentValue);
        }
    
    }
    

    Page

    protected void Page_Load(object sender, EventArgs e)
    {
        var ds = new[]
        {
            new { FirstName = "F1", LastName = "L1" },
            new { FirstName = "F2", LastName = "L2" },
        };
    
        DataList1.DataSource = ds;
        DataList1.DataBind();
    }
    

    Html Markup

    <asp:DataList ID="DataList1" runat="server">
        <ItemTemplate>
            <uc1:Test ID="Test1" runat="server" CurrentValue='<%# Eval("FirstName") %>' />
        </ItemTemplate>
    </asp:DataList>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create my own user control which only contains a panel : When I
I have a property of type IEnumerable<SomeClassIWrote> in a user control. When I use
I am designing a WPF user control which contains other user controls (imagine a
I have Designed the Javascript function My.js it contains following code My.js function display(){
In one of the user controls in our project we have an obsolete property
I have designed database tables (normalised, on an MS SQL server) and created a
Our rails app is designed as a single code base linking to multiple client
I have a poorly designed database. One of the most important tables has 11,000+
I initially designed my system following the s# architecture example outlined in this codeproject
Why was C# designed this way? As I understand it, an interface only describes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.