.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Problem in Custom Control Unable to find Control To Validate Property

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :ASP.Net

I make a custome control by taking a TextBox and A Regular Expression Validator.When i Use this on a .aspx page it works fine.But when i use this on .ascx page and dynamically load user control on a place holder in .aspx page it through an Error

Unable to find control id '_ctl0:txtEmail' referenced by the 'ControlToValidate' property of '_ctl0:txtEmailRequired'


My Custome control Code is this"--

public class EmailValidator:System.Web.UI.Control, INamingContainer{

private System.Web.UI.WebControls.TextBox textBox;

private System.Web.UI.WebControls.RegularExpressionValidator regularExpressionValidator;

public EmailValidator(){

textBox = new TextBox();

regularExpressionValidator = new RegularExpressionValidator();

IsErrorTextBelow = true;

IsRequired = false;

View Complete Post

More Related Resource Links

Custom Server Control Property not maintaining state


I have created a server control consisting of a TextArea and a div under it.  My goal is to create my own asp:TextArea type control.  the div is for a Character count of the text area and seems to work ok but i added a CharacterCountVisible property to the control that is always returning true.  See Proptery definition below


<Bindable(False), Category("Appearance"), DefaultValue("True"), Localizable(True)> Property CharacterCountVisible() As Boolean
        Return _CountBoxVisible
    End Get
    Set(ByVal value As Boolean)
        _CountBoxVisible = value
    End Set
End Property

Note the _CountBoxVisible variable is define inside the class as :

Dim _CountBoxVisible as Boolean = True

What I am trying to do is give the user/coder the option to show/utilize the char count feature.  Can make it disappear with textarea1.CharacterCountVisible = False but setting it to true will not make it display.


What am i missing





Problem binding business objects to custom user control properties

I have created a user control (supplierPicker) intended to allows a supplier database to be searched and a supplier selected. I want to be able to use this control in a number of other user controls, by binding the suppplierID property of the supplierPicker to a supplierID property in a business object, which is set as the datacontext of the parent user control. When I do this, and there is a supplierID specified in the business ofbject, the binding sets the supplierID in the supplierPicker control and it shows the correct supplier name in the textbox. However when the supplierID DependencyProperty is changed from within the supplierPicker the newly selected supplier name is shown in the TextBox, but the SupplierID does not propogate back to the business object. Other controls on the parent form work fine, so the binding to the business object seems to be ok. Any pointers as to what I'm doing wrong here would be grately appreciated.  This one has been driving me nuts for days! Snipped code for the supplier picker:         public partial class SupplierPicker : UserControl, INotifyPropertyChanged     {         public static DependencyProperty SupplierIDProperty;         public event PropertyChangedEventHandler PropertyChan

unable to trace value after postback within Custom Server Control

public class TextBox : AStateManagement, IControl { #region "Variables" #region "Local Variables" protected System.Web.UI.WebControls.WebControl _TextBox = null; protected string _CssClass = string.Empty; protected string _Text = string.Empty; protected bool _Visible = true; protected bool _Enabled = true; protected string _ID = string.Empty; protected bool _IsViewStateLoaded = false; #endregion "Local Variables" #region "Global Variables" #endregion "Global Variables" #endregion "Variable" #region "Constructor" public TextBox() { _TextBox = new System.Web.UI.WebControls.TextBox(); _TextBox.ID = this.UniqueID; } #endregion "Constructor" #region "Events" #endregion "Events" #region "Disposable" #endregion "Disposable" #region "Properties" public override string CssClass { get { return _CssClass; } set { _TextBox.CssClass = _CssClass = value; } } public virtual string Text { get { return _Text; }

Unable to Set Control's Property After Update / PagePostBack


I'm trying to programmatically set the property of a control on my Form AFTER I've proccessed an update command using the FormView, but it's not working. 

In my example below, I have a basic FormView with only a TextBox and Label in its EditItemTemplate.  The FormView uses an AccessDataSource.  The TextBox is bound to the datasource, but the label is not.  What I'm trying to do is update the value in the TextBox (as well as its associated data stored in the database), and then change the Text property of the Label. (*Note: that I using the label purely as an example. The point is I can't see to set any control's property after an update).

I initally thought it had something to do with the "Page.IsPostBack", but even after trying to adjust my code for that, its still not working.

I've tried change the Text property during the Page.IsPostBack during Page_Load event. I've tried setting the Label's EnabledViewState property to True and to False. I've tried using the FormView's OnItemUpdating and OnItemUpdated events. I've tried using the DataSource's OnUpdating and OnUpdated events.

Nothing seems to work. Any suggestions?

Here's my sample code and Html:

<script language="VB" run

Unable to find Control in List



I'm trying to define the parameters of my data source using a stored procedure. My Stored Procedure Syntax is perfect and i'm happy with that, i've just got trouble with connecting my parameters to my controls. I have 19 Parameters, of which i've managed to connect 17 to controls within my ASP.Net form (some to text boxes, some to ddls etc...)

However, i'm trying to connect a particular parameter to a control, but when i drop down my list of controls it's not visible? The control is within a hidden panel so i've un-hidden it and it's still not there. I've even commented out the panel and tried that but i can't find this control! I just cant seem to get this control to appear in the list.

Has any one seen anything like this before at all?

If you need any more information please let me know. (for clarirty i've attached screen grab)

Control Not in list


Problem with property editor of a web user control



I created an asp.net user control with a property named 'TabList' , the property is visible when I place my control on a page, the default editor for this property was a simple text box, but I needed a DropDownList for editing the TabList property of my control, so I added following code to implement it:

<Category("Navigation Bar"), Editor(GetType(DropDownList), GetType(System.Drawing.Design.UITypeEditor)), Description("List of Tabs"), DefaultValue("SHISHIR WAHI")> Public Property TabList() As String
            Return _tablist
        End Get

        Set(ByVal value As String)
            _tablist = value
        End Set
    End Property

The Category() and DefaultValue() are working fine but Editor() and Description() are not, what could be the problem?

Please help.

How to find the resources from Custom Control



    I Created one custom control, i am using that control in some places. but i want to acess that controls(For example button, which is in custom control) in where i am using. how i can fetch that controls. please any one help me.



Asp.net security problem for Captcha custom control


Hi, I downloaded the source code and followed the instruction to include a captcha control in my asp.net site's from:http://www.mondor.org/captcha.aspx  in my create user control. It was working well but when I implemented Asp.net role base sitemap, This security perventing me showing this captha image. Based on provided security all other portion of the 'create user control' is showing except the captcha image.

One solution is the create a separate folder for this page and ont include a web.config for authorization any other solution so that I keep the page in it's place.

Unable to find control with id



I write a webcontrol with a label and a textbox

I use the AssoiactedControlId property to link the textbox to the label
See the Render method below :

protected override void RenderContents(HtmlTextWriter output)
	HtmlGenericControl hgcDiv = new HtmlGenericControl("div");

	TextBox tbNumberLot = new TextBox();	
	tbNumberLot.ID = "tbNumberLot";

 	Label lNumberLot = new Label();
	lNumberLot.ID = "lNumberLot";
	lNumberLot.AssociatedControlID = tbNumberLot.ID;



this throw an exception :"Unable to find control with id 'tbNumberlot' that is associated with the label &#

Custom checkbox control 'checked' property is not working .


Hello ,


Iam developing a custom checkbox control deriving from the 'compositecontrol' which i need to use it for a composite control purpose.



public class TngCheckBox : CompositeControl


i have written the required properties which are working fine except the "checked" property. he

Accessing Property Value of a Custom Control by another Custom Control in Design-time



I created an Extender which has a custom property that drills down a list XML elements from an xml file, where users can select xml elements during design-time. This works perfectly fine. However, my code only has a hardcoded xml filename (source of the xml elements list) and I need to change this by maxing the xml file user-specified.

What I did is that I created another control (panel) which has a custom property that when clicked (through the ellipsis), it will allow a developer to select the xml file which is supposed to be the source xml file that the Extenders shall use. The filedialog from custom panel's property works perfectly fine.

However, my problem now is that when I drag-drop my Extender, I cannot find a way to get the property value of the custom Panel Control which contains the xml filename. I tried creating a static variable which I thought the custom controls can share but VS2010 is breaking.

Please take note that my problem is on Design-time, asp.net.

Appreciate any help. Thanks a lot.

Dhon Nuevo.

Unable to find Control ID of Dropdownlist Control of a UserControl from a ContentPage


I am implementing Master Pages in my existing project.

I am getting following Error:

" Unable to find control id '_ctl0:ContentPlaceH?older1:drop1:drop1' referenced by the 'ControlToValidate' property of 'valCust1'. "

I have a ContentPage which is refering to a UserContol. This UserControl has a DropDownList Control which i need to validate.

I am using a CustomValidator to validate the Dropdownlist and this CustomValidator is placed in the ContentPage.

The ControlToValidate Property of the CustomControl is assigned programatically as
(in ASPX.cs)

Control CTRL1;

ContentPlaceHolder cntplcHolder = (ContentPlaceHolder)?this.Master.FindCont?rol("ContentPlaceHol?der1");

 CTRL1 = cntplcHolder.FindCon?trol("drop1").FindCo?ntrol("drop1");

 valCust1.ControlToValidate = CTRL1.UniqueID;

My .ASPX page contains

<%@ Register TagPrefix="it" TagName="PickCntl1" Src="~/UserControls/?PickCntl1.ascx" %>

<it:PickCntl1 id="drop1" Runat="Server" Required="true" DisplayDefault="true?"></it:PickCnt?l1>


custom control validator - can't set width property


 I am trying to set the width property of a custom control validator but it is not happening at all. The width of the validator control popup is constantly 100% width (the width="200px" below has NO effect at all)

here is my code:

 < asp:RequiredFieldValidator id="RqdDateChange" 
ControlToValidate="txtDateChange" ErrorMessage="<b>Required Field Missing</b><br />The Date of Change is required.&quo

Need Custom Text Box Control with DataSource,TableName,ColumnName Property


I need to create one custom text box control which should be bind with data base.

I am referring following link...


I used DataBoundControl to create my control but i am not able to do it properly.

    public class SimpleTextBoxControl : DataBoundControl
        private TextBox nameTextBox;

        public string DataTextField
                object o = ViewState["DataTextField"];
                return ((o == null) ? string.Empty : (string)o);

How to get javascript 'value' property for custom textbox control


I created one custom control which contains TextBox as a child control (and contains some other controls? also). After this I placed this control in a Page and I'm trying to get TextBox value(i.e text) through javascript. But I'm unable to get 'value' property directly.

Custom Control code:????

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace AjaxServerControlDevelopment
    public class MyTextBox: CompositeControl
        /// <summary>
        /// TextBox reference variable
        /// </summary>
        public TextBox objTextBox;

        /// <summary>
        /// The TextChanged event
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1009:DeclareEventHandlersCorrectly")]
        public event EventHandler TextChanged;

        /// <summary>
        /// The ButtonClick event
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1009:DeclareEventHandlersCorrectly")]
        public event EventHandler<EventArgs> ButtonClick;

            #region Class constructors

        /// <summary>
        /// Default constructor

File Upload custom Control problem


Hello All,

I am trying to build a custom control that requires that all the uploaded files should in the database.  I have saved them successfully but when i retrieve them using Generic Handler then the image is always shown broken. I have tried alot but this happens again. Below is my code of the handler.


<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.IO;

public class Handler : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        //SqlConnection con = new SqlConnection();
        //con.ConnectionString = ConfigurationManager.ConnectionStrings["connString"].ConnectionString;
        SqlConnection con = new
          SqlConnection(@"server=BEHROZ\SQLEXPRESS;database=UserControl;Integrated Security=SSPI;");

        // Create SQL Command 
        DataTable dr = new DataTable();

        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "Select Image from TempImage";
        cmd.CommandType = System.Data.CommandType.Text;
        cmd.Connection = con;


        SqlDataAdapter sa = new SqlDataAdapter(cmd);
        SqlDataReader dReader = cmd.ExecuteReader();

find a Control inside a GridView using jQuery


I have databound GridView in my page and I have a hidden DIV in all rows. Each row contains a Button that I want it to make the DIV visible for me! how can I use that with jQuery?!

here is the code page: 

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                                EnableModelValidation="True" GridLines="None" ShowHeader="False" Width="100%">
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend