Textbox

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Textbox as PDF for free.

More details

  • Words: 867
  • Pages: 7
TextBox: 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?



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



28.11 How to display data in Textboxes using DataSet?

Product ID : Product Name:

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 : Name :

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? You can use the TextBox webserver control and set the TextMode = MultiLine 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?

runat="server">

VB.NET

Protected colCon As New System.Drawing.ColorConverter Protected bgcolor As String = "#556600" 'In Page_Load Page.DataBind()

C#

protected System.Drawing.ColorConverter colCon =new System.Drawing.ColorConverter(); protected string bgcolor = "#556600"; //In Page_Load Page.Databind();

28.17 How to create an array of Web Controls?



VB.NET

Dim textboxes(5) As TextBox Dim i As Integer For i = 0 To 4 textboxes(i) = New TextBox() textboxes(i).ID = "TextBox" + i textboxes(i).AutoPostBack = True PlaceHolder1.Controls.Add(textboxes(i)) Next

C#

TextBox[] textboxes = new TextBox[5]; for (int i=0; i<5; i++) { textboxes[i] = new TextBox(); textboxes[i].ID = "TextBox" + i; textboxes[i].AutoPostBack = true; PlaceHolder1.Controls.Add(textboxes[i]); }

28.18 How to show TextBox web server control with TextMode Property Password as **** rather than blank? For security reason, TextBox with TextMode="Password" setting cannot be assigned or populated via the Text property on Page_Load or PostBack event. It's not recommend for to prefill a "Password" type TextBox with the("***") characters, though below is the solution to achieve this. VB.NET

ViewState("Pwd")=TextBox1.Text ; TextBox1.Attributes.Add("value", ViewState("Pwd").ToString ()) ;

C#

ViewState["Pwd"]=TextBox1.Text ; TextBox1.Attributes.Add("value", ViewState["Pwd"].ToString ()) ;

Related Documents

Textbox
November 2019 5
Textbox And Button
October 2019 4
De Bd A Textbox
May 2020 4
Textbox Validation Js
November 2019 5