z
 
:: Home     :: MS Dynamics CRM     :: .Net 1.1     :: .Net 2.0     :: Sharepoint Portal     :: Ajax

  login:        
  passwords:  
 

Resources

Finding Correct Content Managemet System
This list covers the full lifecycle of a content management system, from initially creating the content, through to delivering it to end users...

Workflow Managemet Systems
Workflow management is a crucial component in organizing a variety of business processes so that they benefit the business as a whole and increase profitability...

Using the Power of Content Management Systems
With page editors that resemble a word processor program, adding content with a CMS interface is simple and fun. Most CMS software also allows you to change the location of your content pages and links easily, while the back end processes takes care of updating the links throughout your site...

Content Management Systems (CMS): What They Are And Why We Love Them
In the past, individuals who took interest in having and operating their own websites were burdened with the task of learning HTML, DHTML, and other web-based technologies such as JavaScript and CSS. The only alternative to this was, unfortunately, to pocket the expenses and costs required to pay a web developer to build and maintain it for them...

Outsourcing
Post your project for outsourcing and get bids from qualified programmers, designers, interpreters, copywriters.


 

Code Walkthroughs

Datagrid Formatting the Data
We are able to format the content of the datagrid cell by one of two simple methods, dependant upon whether the column is a bound column or whether it is a template column. In our example we shall format the column to have to digits after the decimal point , followed by a...

Datagrid Highlight a Row With Click Through
It is relatively easy to add alternating colours to the rows in your datagrid. However, when we move the mouse over the rows we may want to highlight this row, and possibly to add the option of a click through based on the row selected...

Add a Delete Button to a Datagrid
To add a delete button to a datagrid follows a similar process to adding an edit button. In the datagrid header...

Add an Edit Button to a Datagrid
The datagrid has a predefined editColumn for handling the editing of a datagrid. Adding this simple column definition to a datagrid adds a powerful feature. When a row is not in edit mode the column item shows the word...

Making a Datagrid Row Editable
Two of the most popular methods of editing a datagrid in asp.net are to either select the row and take the user off to a different presentation of the data, or to change the formatting of the row presented in the database with appropriate edit text boxes, checkboxes and...

Adding Tooltips to Datagrid Rows
Adding tooltips to datagrid rows is easy, assuming that you have already created the code for adding row highlighting. In this article I shall assume that you have already read the article entitled Datagrid Highlight a Row With Click Through...

Binding a Datagrid to an Access Database
This list covers the full lifecycle of a content management system, from initially creating the content, through to delivering it to end users...

Adding Data to a DropDownList
The aim of this article is to answer the question 'How do I add items to a DropDownList?' Initially as part of the declaration for the DropDownList we can also define a number of items, much in the same way as in classic ASP...

Getting Current Date Time
In classic ASP we had now() which would return the current date and time. For asp.net this no longer exists. So what should we use...

Test if File Exists
Sometimes, in order to reduce our chance of error, when working with the filesystem in ASP.NET, we need to determine wether a file exists before performing an action on it. The following short piece of code will enable us to test whether a file exists...

Using Javascript with ASP.NET Form Elements
Adding simple pieces of Javascript to an Asp.net page can be acheived by adding to the attributes of the particular imagebutton or linkbutton. if its normal ASP.Net Button then you can...

Regular Expressions
In the table below we list the characters used in .Net regular expressions, together with their meaning, But first...

Authentication in Asp.net
Forms authentication in ASP.Net is far more easier and safe than Asp 3. It is possible to place a web.config file in any directory of a web site.Therefore, we are able to make most of a web site public, whilst providing authentication on, say, one directory...

Discussion Forums

General ASP.NET

.Net Programming

cSharp Home

Sql Server Home

Javascript / Client Side Development

IT Jobs

Ajax Programming

Ruby on Rails Development

Perl Programming

C Programming Language

C++ Programming

Python Programming Language

Laptop Suggestions?

TCL Scripting

Fortran Programming

Scheme Programming

28. TextBox

FAQ Home
   28.1 How to cast the value entered in a textbox to integer?
   28.2 How to allow only numeric values in a textbox using ASP.NET Validator control?
   28.3 Why does TextBox retain its values when posting inspite of having ViewState property disabled for TextBox,?
   28.4 I am running the query SQL="Select name from profile where proID=1"; and I am getting the result in Dataset dsdata. How can I read the text from the dataset and assign it to textbox1.text ?
   28.5 How to align the Text property of the Textbox Control?
   28.6 Why do I get error message "Option Strict On disallows implicit conversions from 'System.Web.UI.Control' to 'System.Web.UI.WebControls.TextBox'."?
   28.7 How to convert TextBox value into a DateTime variable?
   28.8 How to clear all the textboxes in my form?
   28.9 How to programmatically set the width of the textbox control?
   28.10 How to get the textbox value at the client side ?
   28.11 How to display data in Textboxes using DataSet?
   28.12 How to display data in Textboxes using DataReader?
   28.13 Is there a TextArea in ASP.NET?
   28.14 How to right align the text in the TextBox?
   28.15 How to force the max no. of lines in a multiline TextBox using RegularExpressionValidator?
   28.16 How to change server control backcolor from a variable?
   28.17 How to create an array of Web Controls?
   28.18 How to show TextBox web server control with TextMode Property Password as **** rather than blank?



28.1 How to cast the value entered in a textbox to integer?


VB.NET


Int32.Parse(TextBox1.Text)


C#


Int32.Parse(TextBox1.Text);



28.2 How to allow only numeric values in a textbox using ASP.NET Validator control?



<asp:TextBox id="txtNumber" Runat="server" />
<asp:RegularExpressionValidator ID="vldNumber" ControlToValidate="txtNumber" Display="Dynamic" ErrorMessage="Not a number" ValidationExpression="(^([0-9]*|\d*\d{1}?\d*)$)" Runat="server">
</asp:RegularExpressionValidator>




28.3 Why does TextBox retain its values when posting inspite of having ViewState property disabled for TextBox,?


Refer to Teemu Keiski's blog ASP.NET: TextBox and EnableViewState="False"


28.4 I am running the query SQL="Select name from profile where proID=1"; and I am getting the result in Dataset dsdata. How can I read the text from the dataset and assign it to textbox1.text ?


VB.NET


Textbox1.Text= dsData.Tables(0).Rows(0)("FieldName").ToString()


C#


TextBox1.Text=dsData.Tables[0].Rows[0]["FieldName"].ToString();



28.5 How to align the Text property of the Textbox Control?


VB.NET


TextBox1.Style("text-align")="right"


C#


TextBox1.Style["text-align"]="right";



28.6 Why do I get error message "Option Strict On disallows implicit conversions from 'System.Web.UI.Control' to 'System.Web.UI.WebControls.TextBox'."?


For type Casting apply the following steps

VB.NET


dim aprtxt as string
aprtxt= CType(e.Item.FindControl("txtapr"), TextBox)


C#


string aprtxt;
aprtxt = (TextBox) e.Item.FindControl["txtapr"];



28.7 How to convert TextBox value into a DateTime variable?


VB.NET


Dim dt As DateTime = DateTime.Parse(TextBox1.Text)


C#


DateTime dt = DateTime.Parse(TextBox1.Text);


By default Date.Parse check the date as MDY format Refer DateTime.Parse for a specified Date Format.


28.8 How to clear all the textboxes in my form?


VB.NET


Dim ctl As Control
For Each ctl In Page.Controls(1).Controls
If TypeOf ctl Is TextBox Then
CType(ctl, TextBox).Text = ""
End If
Next


C#


foreach (Control ctl in Page.Controls[1].Controls )
{
     TextBox tb = ctl as TextBox;
     if (tb!=null)
     {
     tb.Text = "" ;
     }
}


Note: Page.Controls[1]=> control is within the form tag


28.9 How to programmatically set the width of the textbox control?


VB.NET


TextBox1.Width = Unit.Pixel(100)


C#


TextBox1.Width = Unit.Pixel(100);



28.10 How to get the textbox value at the client side ?



<script lang="javascript">
function CheckFunction()
{
if (document.getElementById('<%=textbox2.ClientID%>').value == "")
{
     alert("Please enter a value");
     return;
}
}
</script>



<asp:textbox id="textbox2" runat="Server"></asp:textbox>
<input type=button id="btn1" onclick="javascript:CheckFunction();" value="Click">




28.11 How to display data in Textboxes using DataSet?



Product ID : <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 80px; POSITION: absolute; TOP: 64px" runat="server"></asp:TextBox>
Product Name:<asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 80px; POSITION: absolute; TOP: 112px" runat="server"></asp:TextBox>


VB.NET


'Populate the DataSet
'...

'Display in TextBoxes using Column Name
TextBox1.Text = ds.Tables (0).Rows(0)("ProductId").ToString ();
TextBox2.Text =ds.Tables (0).Rows(0)("ProductName").ToString ();

'Display in TextBoxes using Column Index
TextBox1.Text = ds.Tables (0).Rows(0)(0).ToString ();
TextBox2.Text =ds.Tables (0).Rows(0)(1).ToString ();


C#


//Populate the DataSet
//...

//Display in TextBoxes using Column Name
TextBox1.Text = ds.Tables [0].Rows[0]["ProductId"].ToString ();
TextBox2.Text =ds.Tables [0].Rows[0]["ProductName"].ToString ();

//Display in TextBoxes using Column Index
TextBox1.Text = ds.Tables [0].Rows[0][0].ToString ();
TextBox2.Text =ds.Tables [0].Rows[0][1].ToString ();




28.12 How to display data in Textboxes using DataReader?



Id : <asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 128px; POSITION: absolute; TOP: 32px" runat="server"></asp:TextBox>
Name : <asp:TextBox id="TextBox2" style="Z-INDEX: 103; LEFT: 128px; POSITION: absolute; TOP: 72px" runat="server"></asp:TextBox>


VB.NET


Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim rdr As SqlDataReader

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     ' Put user code to initialize the page here
     Try
          cn=NewSqlConnection("server=localhost;uid=sa;pwd=;database=northwind")
          cmd = New SqlCommand("select * from Products where productid =1", cn)
          cn.Open()
          rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
          rdr.Read()
          TextBox1.Text = rdr("ProductId").ToString()
          TextBox2.Text = rdr("ProductName").ToString()
     Catch ex As Exception
          Response.Write(ex.Message.ToString())
     Finally
          rdr.Close()
          cn.Close()
     End Try
End Sub


C#


SqlConnection cn ;
SqlCommand cmd ;
SqlDataReader rdr ;
private void Page_Load(object sender, System.EventArgs e)
{
     // Put user code to initialize the page here
     try
     {
          cn=newSqlConnection("server=localhost;uid=sa;pwd=;database=northwind");
          cmd = new SqlCommand( "select * from Products where productid=1 ", cn);
          cn.Open();
          rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection );
          rdr.Read ();
          TextBox1.Text =rdr["ProductId"].ToString ();
          TextBox2.Text =rdr["ProductName"].ToString ();
     }
     catch (Exception ex)
     {
          Response.Write (ex.Message.ToString ());
     }
     finally
     {
          rdr.Close();
          cn.Close();
     }
}



28.13 Is there a TextArea in ASP.NET?