.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

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

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net

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

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 in Custom Control Unable to find Control To Validate Property


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;

How to create a Custom TextBox Control to provide the custom functionality



I have a requirement that I need to develop a custom textbox control which should support the functionality like:

1. Should display the Default Cursor as Cross Cursor

2. Textbox should be displayed like excel sheet cell (specific to cell) and when user will click the TextBox it should be selected but can not be entered any data inside.

3. Context Menu should be displayed with some information while double clicked on the TextBox but should not be edited the textbox.

4. Context Menu should be displayed if right click on the TextBox

6. TextBox should be on entry mode if user presses any ALPHNUMERIC key from Keyboard.

7. DataValidation should be there when user enters any data.

Can anyone help me on this how to develop such kind of control or May be somebody has already done those things and can give me a hint...

Thanks in advance for the help.



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.

Embedded Javascript File in Custom Server Control



I am creating a custom server control, and I am wanting to include a JavaScript file in the dll file when the control is built. I have tried suggestions from the following websites:




But after following the directions, If I use firebug to see what errors show up, the JavaScript functions that are being called all say "goNext is not defined" which leads me to believe the JavaScript file is not being added correctly. 

Some information on what my control looks like

I have the JavaScript File in a folder called Script. The namespace of the project is CustomControl, and the Name of the project is MaskedDateTextbox.

In my AssemblyInfo I have the following:

find textbox control of gridview using javascript



 I am inserting a data in gridview row. I have 2 textbox's, 1 label and 1 textbox respectively. Here, I want to do calculations on data which is in first two textboxes and result should be displayed in label and the text in label to be multiplied with 40 and that should be displayed in last textbox.

 This operation to be done in onblur() event of second textbox. To do this I need to find the controls in gridview in onblur() event of the textbox.

  I tried to do this in .cs file but this operation is to be done before inserting in to database on that particular row of gridview.

I searched on the net but i couldn't find the solution. I couldn't know how to find textbox of a gridview using javascript

Please help me.....

Set value of TextBox in User Control from Javascript



I have a page with a user control. I'm trying to populate the values of the textboxes in the User control from javascript in the main page.


Screen Interface is as follows:

Sponsor Type: [ ddlbSponsorType   ]

Event: [   TextBoxEvent   ]

Sponsor:  Company Id  : 

                Company Name  :  [  TextBoxCompanyName   ] [Look Up button]

                Contact Person Last Name  :  [  TextBoxPersonLastName  ]

                Contact Person First Name  :  [  TextBoxPersonFirstName   ]

                Contact Person Email  :  [  TextBoxPersonEmail ]


Company Id, Company Name, Contact Person fields are all embedded in a user control.  From Javascript, can you let me know how I can populate the company fields.  Using the document.getElementById seems to assign the correct values when I alert the values afte

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);

Need to know about the kind(button, textbox, list or combo) of .NET control after custom based seria



In the process of serializing .NET control object to custom object( sayMyControlObject) to the other process for some purpose , I need to re-draw these controls in custom manner. For that I need to know what type it is like ( its is button, textbox, combo box, TextField, Calander, ToolStrip,TtoolstripMenu,RichTextBox,TabControl or TreeView it is). For that I might need sort of typeOf(RichTextBox) == RichTextBox sort of check.

I will be very obliged and thankfull , if any body having idea about this?

Regards Usman

Need to know about the kind(button, textbox, list or combo) of .NET control after custom based seria



In the process of serializing .NET control object to custom object( sayMyControlObject) to the other process for some purpose , I need to re-draw these controls in custom manner. For that I need to know what type it is like ( its is button, textbox, combo box, TextField, Calander, ToolStrip,TtoolstripMenu,RichTextBox,TabControl or TreeView it is). For that I might need sort of typeOf(RichTextBox) == RichTextBox sort of check.

I will be very obliged and thankfull , if any body having idea about this?

Regards Usman

Custom Editing Behavior for DataGridView TextBox Columns

For various reasons I'm using a DataGridView instead of a ListView, and while configuring the DataGridView to look like a ListView wasn't much of a problem, there's one thing that got on my nerves, which is the behavior of textbox cells in edit mode: It is much too easy to leave the edit mode accidentally, simply by pressing the cursor keys at the wrong time. For example when the text caret is positioned behind the last character of the textbox cell content, and you press the right arrow key

watermark textbox using Ajax control

This is pretty simple compared to jquery. Since we need refer a dll only. we dont want any script for this. we just include that reference into our website.

how to get an array of all the asp.net textbox control inside create user wizard control?



How can I get all the textboxes inside a create user wizard control using getElementsByTagName().

Below is my JQuery code:

<script type="text/javascript">
        function addLoadEvent(func) {
            var oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            } else {
                window.onload = function() {

        function prepareInputsForHints() {
            var inputs = document.getElementsByTagName("asp:TextBox");
            for (var i = 0; i < inputs.length; i++) {
                inputs[i].onfocus = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
                inputs[i].onblur = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "none";



<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

Content page control passes as argument to javascript function


Here is the content page:


<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="JavaDynamicCopyValue.aspx.cs" Inherits="JavaDynamicCopyValue" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
 <script type="text/javascript" >
 function copyValue(input, output )
   ouput.value = input.value;
   return true;
 <asp:TextBox ID="txt1" runat="server" onchange="copyValue(this,document.getElementById('<%=txt2.ClientID%>'))"></asp:TextBox>
    <br />
    <br />
    <asp:TextBox ID="txt2" runat="server"></asp:TextBox>


I got a javascript run time error says output is undefined. if I view source of the page, the txt1 markup became:

<input name="ctl00$ContentPlaceHol

Custom Control Design-Time SiteMap Provider Error


Greetings - I was referred here by MSDN forums hope this is the right place -  

I have a custom control (:WebControl) that renders web.sitemap in a specific way. While it runs error free and produces the expected result, at Design-Time it complains

Error Creating Control - MyControl  The provider 'AspNetXmlSiteMapProvider' specified for the defaultProvider does not exist in the providers collection.

I have discovered that the error is cause by this line of code:

string div = string.Format("<div class='{0}' id='{1}'>{2}</div>", this.CssClass, this.ID.ToString(), EnumerateNodesRecursive(SiteMap.RootNode, level));

or more specifically, by the reference to SiteMap.RootNode - I am not clear what is missing thoough because I have configured the SiteMapProvider in web.config as this:

        <add name="AspNetXmlSiteMapProvider" 
             type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
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