Skip to main content

ASP.NET Textbox Tips

This page is to describe all tips and tricks of asp.net controls. We have number of asp.net server controls which we use regularly and may miss few things and will search a lot for the tip or trick to handle the situation such situation we will discuss regularly.

This page discusses about the basic asp.net control textbox

The syntax for the textbox is as below

Syntax:

<asp:TextBox runat="Server" ID="txtName"></asp:TextBox >

It is a input field means from which users can input data and will be used by our application to process it.

Rendering: 

It renders as normal HTML input element of type text

TIP#1- Accessing Textbox from Javascript:

    As it renders as HTML element to the user browser any HTML element can be accessed by Javascript so we can access this control too. Only what we need is to know the element id after rendering. For that asp.net provided us a very good property for dealing with client ids. i.e.<control>.ClientID which will return us the rendered element id.

Example:

  <asp:TextBox runat="server" ID="txtName"></asp:TextBox>
  <script type="text/Javascript">
      var elm = document.getElementByID('<%=txtName.ClientID%>');
  </script>

from the above script we can perform all kinds of operation that we can do for a normal input field from Javascript like accessing or assigning a value to textbox, enable or disable textbox, changing the style of textbox, validating the user input in the textbox

Comments

Popular posts from this blog

Creating package in Oracle Database using Toad For Oracle

What are Packages in Oracle Database A package is  a group   of procedures, functions,  variables   and  SQL statements   created as a single unit. It is used to store together related objects. A package has two parts, Package  Specification  and Package Body.

Resolving 'Setup Account Privileges' error while installing SQL Server

A new installation of Microsoft SQL Server 2012 or Microsoft SQL Server 2008 R2 fails You see the following error message when you try to install a new instance of SQL Server 2012 or SQL Server 2008 R2: Rule "Setup account privileges" failed.

Creating Oracle stored Procedures using TOAD for Oracle

In a database management system, a  stored procedure  is a set of Structured Query Language (SQL) statements with an assigned name that's stored in the database in compiled form so that it can be shared by a number of programs. The use of  stored procedures  can be helpful in controlling  access to data, preserving  data integrity  and  improving  productivity.