Académique Documents
Professionnel Documents
Culture Documents
VB.NET
Int32.Parse(TextBox1.Text)
C#
Int32.Parse(TextBox1.Text);
28.3 Why does TextBox retain its values when posting inspite of having
ViewState property disabled for TextBox,?
VB.NET
Textbox1.Text= dsData.Tables(0).Rows(0)("FieldName").ToString()
C#
TextBox1.Text=dsData.Tables[0].Rows[0]["FieldName"].ToString();
VB.NET
TextBox1.Style("text-align")="right"
C#
TextBox1.Style["text-align"]="right";
VB.NET
C#
string aprtxt;
aprtxt = (TextBox) e.Item.FindControl["txtapr"];
VB.NET
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.
VB.NET
VB.NET
TextBox1.Width = Unit.Pixel(100)
C#
TextBox1.Width = Unit.Pixel(100);
<script lang="javascript">
function CheckFunction()
{
if (document.getElementById('<%=textbox2.ClientID%>').value == "")
{
alert("Please enter a value");
return;
}
}
</script>
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
C#
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
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();
}
}
You can use the TextBox webserver control and set the TextMode = MultiLine
28.15 How to force the max no. of lines in a multiline TextBox using
RegularExpressionValidator?
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 0px; POSITION: absolute; TOP: 112px"
runat="server" TextMode="MultiLine"></asp:TextBox>
<asp:RegularExpressionValidator id="RegularExpressionValidator1" style="Z-INDEX: 102; LEFT: 216px;
POSITION: absolute; TOP: 112px"
runat="server" ErrorMessage="MaxLength is 20" ControlToValidate="TextBox1"
ValidationExpression="^\w{1,20}$">
</asp:RegularExpressionValidator>
28.16 How to change server control backcolor from a variable?
VB.NET
'In Page_Load
Page.DataBind()
C#
//In Page_Load
Page.Databind();
VB.NET
C#
For security reason, TextBox with TextMode="Password" setting cannot be assigned or populated via the Text
It's not recommend for to prefill a "Password" type TextBox with the("***") characters, though below is the
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 ()) ;