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

Asp.Net Web API

What is ASP.NET Web API? ASP.NET Web API is a framework provided by the Microsoft with which we can easily build HTTP services that can reach a broad of clients, including browsers, mobile, IoT devices, etc. ASP.NET Web API provides an ideal platform for building RESTful applications on the .NET Framework.   Difference between ASP.NET Web API and WCF Web AP I is a Framework to build HTTP Services that can reach a board of clients, including browsers, mobile, IoT Devices, etc. and provided an ideal platform for building RESTful applications. It is limited to HTTP based services. ASP.NET framework ships out with the .NET framework and is Open Source. WCF i.e. Windows Communication Foundation is a framework used for building Service Oriented applications (SOA) and supports multiple transport protocol like HTTP, TCP, MSMQ, etc. It supports multiple protocols like HTTP, TCP, Named Pipes, MSMQ, etc. WCF ships out with the .NET Framework. Both Web API and WCF can be self-hosted or can be...

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.