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 8142941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:57:41+00:00 2026-06-06T12:57:41+00:00

Old Title: Prevent dynamically created control from retaining value Old Info: The reason I

  • 0

Old Title: Prevent dynamically created control from retaining value

Old Info:
The reason I need to do this is because I am trying to create a work around for a required field validator for an Image control. The way my code works is I have a Image control beside a Button, a user clicks on the button and then is prompted to upload an image. I need to ensure that an image is uploaded before the user can move onto the next stage.

Since there is no required field validator for an image control, I created a textbox which is suppose to display the imageURL of the image control every time the image control is recreated on postbacks. However, the textbox always retains the value from the initial creation of the control.

* Note: all controls on the page are dynamically created.

The first thing I do is create the image control and add it to an HTML Table. This works fine. Right after that I find the table cell and add the textbox to the cell that has an image control:

HtmlTableCell tc = (HtmlTableCell)customProperties.FindControl("tcControl_" + (i + 1).ToString());
RadBinaryImage rbi = (RadBinaryImage)customProperties.FindControl("CustomControl" + (i + 1).ToString());

TextBox photoValue = new TextBox();
photoValue.ID = "CustomControl" + (i + 1).ToString() + "_txt";
photoValue.Text = rbi.imageUrl;

This occurs everytime I create all the controls. For all the controls they all retain their values, this is the only control which I don’t want this to happen. Does anyone know of how this can be done? Or another way of validating an image control?

Thanks for your time,
All comments/answers are appreciated (:

SOLVED:

I created a modified version of a checkboxlist required field validator that I found here.
Here is the code: I replaced the namespace with ######## for security reasons.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using Telerik.Web.UI;

namespace #######################################
{
    public class RequiredFieldValidatorForImages :
                        System.Web.UI.WebControls.BaseValidator
    {
        private Control _ctrl;

        public RequiredFieldValidatorForImages()
        {
            base.EnableClientScript = false;
        }

        protected override bool ControlPropertiesValid()
        {
            Control ctrl = FindControl(ControlToValidate);

            if (ctrl != null)
            {
                _ctrl = (Control)ctrl;
                return (_ctrl != null);
            }
            else
                return false;  // raise exception
        }

        protected override bool EvaluateIsValid()
        {
            try
            {
                Image rbi = (Image)_ctrl;
                return rbi.ImageUrl != "~/images/noimages.jpg";
            }
            catch
            {
                RadBinaryImage rbi = (RadBinaryImage)_ctrl;
                return rbi.ImageUrl != "~/images/noimages.jpg";
            }
        }
    }
}
  • 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-06-06T12:57:44+00:00Added an answer on June 6, 2026 at 12:57 pm

    Solved:

    I created a modified version of a checkboxlist required field validator that I found here.
    Here is the code: I replaced the namespace with ######## for security reasons.

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using Telerik.Web.UI;
    
    namespace #######################################
    {
        public class RequiredFieldValidatorForImages :
                            System.Web.UI.WebControls.BaseValidator
        {
            private Control _ctrl;
    
            public RequiredFieldValidatorForImages()
            {
                base.EnableClientScript = false;
            }
    
            protected override bool ControlPropertiesValid()
            {
                Control ctrl = FindControl(ControlToValidate);
    
                if (ctrl != null)
                {
                    _ctrl = (Control)ctrl;
                    return (_ctrl != null);
                }
                else
                    return false;  // raise exception
            }
    
            protected override bool EvaluateIsValid()
            {
                try
                {
                    Image rbi = (Image)_ctrl;
                    return rbi.ImageUrl != "~/images/noimages.jpg";
                }
                catch
                {
                    RadBinaryImage rbi = (RadBinaryImage)_ctrl;
                    return rbi.ImageUrl != "~/images/noimages.jpg";
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to upgrade an old CMS to use NHibernate and can't deter from
Well, the title's pretty much it: if I sat a non-techie/my mum/twelve-year old boy/cocker
Scenario: old legacy code in rpg have to consume data from a new web
I use an old Powerbook G4. While trying to update the macports (sudo port
From my old Access days, there was a First() function that allowed you to
Old question title: How to capture events in parent UIViews, such as HUD layers?
Old title: Included PHP doesn't work with JQuery and IE in a function as
I have a Sharepoint 2007 site that is displaying the old/original title in the
as the title says my question would be how to debug old asp code
As the title suggests I'm simply trying to get a named window to come

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.