Ads by Lake Quincy Media
| Next Tip?
Home » Asp.net

Use CSS and JavaScript in textbox in .aspx page

20 March 2010 2,840 views 3 Comments
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Use CSS and JavaScript in textbox in .aspx page.

Create a project and add a new .aspx page and then in the aspx page add the following code in the head section.

<style type=”text/css”>

.uppercase

{

text-transform: uppercase;

}

.lowercase

{

text-transform: lowercase;

}

.capitalize

{

text-transform: capitalize;

}

</style>

And then use the above classes in the code as

Typing Text in UPPERCASE

<br />

<asp:TextBox ID=”TextBox1″ runat=”server” CssClass=”uppercase”></asp:TextBox><br />

Typing Text in lowercase

<br />

<asp:TextBox ID=”TextBox3″ runat=”server” CssClass=”lowercase”></asp:TextBox><br />Typing Text in Capatlize

<br />

<asp:TextBox ID=”TextBox4″ runat=”server” CssClass=”capitalize”></asp:TextBox>

And then when you will type any text in these textboxes then they will appear as per the css class used.

And to use the JavaScript in the .aspx page we need to add the script in the head section and the script in the body section too to use the script we have made in the head section.

The script of head section looks like:

<script type=”text/javascript” language=”JavaScript”>

<!–

function chkNumeric(strString)

// strString is the string passed to be checked

// check for valid numeric strings

{

// strvalidchars defines the set of characters which are valid in a numeric field

var strValidChars = “0123456789.-”;

// strings

var strChar;

// boolresult is the variable which returns true is string is in correct format or false if it is not a valid numeric string

var boolResult = true;

if (strString.length == 0) return false;

// test strString consists of valid characters listed above

for (i = 0; i < strString.length && boolResult == true; i++) {

strChar = strString.charAt(i);

if (strValidChars.indexOf(strChar) == -1) {

boolResult = false;

}

}

return boolResult;

}

// –>

</script>

And the body section will look like

<body>

<form id=”form1″ runat=”server”>

<div>

Checking Numbers in textbox using javascript<br />

<asp:TextBox ID=”TextBox2″ runat=”server”></asp:TextBox>

<br />

<script type=”text/javascript”>

function fun() {

if (document.form1.TextBox2.value.length == 0) {

alert(“Please enter a value.”);

}

else if (chkNumeric(document.form1.TextBox2.value) == false) {

alert(“Please check – the string conatins non numeric value!”);

}

}

</script>

<asp:Button ID=”Button1″ runat=”server” Text=”Button” OnClientClick=”fun()” />

</div>

</form>

</body>

And in the body section I have added the script and a button to use that script.

For more clarifications please view the video at: http://www.jaipurmentor.com/share-tech-videos/viewvideo/6/learning-videos/using-css-and-javascipt-in-textbox.html

Popularity: unranked

Post to Twitter Tweet This Post

Related posts:

  1. Online video on Using CSS and Javascript in TextBox Jaipur Mentor Tweet This Post...
  2. Textbox Properties Textbox Properties In this article I will be talking...
  3. Changing properties of textbox in visual studio 2010 Changing properties of textbox in visual studio 2010 To...
  4. Directive Syntax @ Control Directive Syntax @ Control The @Control directive is used in...
  5. Sending Mails with attachments using Gmail Tweet This Post...

Related posts brought to you by Yet Another Related Posts Plugin.

Ads by Lake Quincy Media

3 Comments »

  • email finder download said:

    [...] Use CSS and JavaScript in textbox in .aspx page | Javascript | MsDotNetMentor [...]

  • finding email ip address said:

    [...] Use CSS and JavaScript in textbox in .aspx page | Javascript | MsDotNetMentor [...]

  • finding email settings said:

    [...] Use CSS and JavaScript in textbox in .aspx page | Javascript | MsDotNetMentor [...]

Leave your response!

You must be logged in to post a comment.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes