.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Highlight contents of textbox with MaskedEditExtender

Posted By:      Posted Date: October 12, 2010    Points: 0   Category :ASP.Net


I have looked all over the place and I haven't found a solution to this. I have a TextBox using the AjaxControlToolkit's MaskedEditExtender, the extender is using the Date mask (99/99/9999). We had modified the toolkit code to support 2-digit year (as seen in this post) which works just fine when the date TextBox initially has no value. But when the date TextBox has an existing date such as 10/04/2010, if I type in say 100409, it becomes 10/04/0910, in other words it doesn't replace the existing year but simply replace the first 2 digits of the year. If I first hightlight the entire field then type then it works. My question is is there a way to hightlight the entire date value of the TextBox upon entering the field? I tried using javascript code textbox.focus() and .selet() but it doesn't highlight anything, it just places the cursor at the beginning of the textbox. Or is there another solution to what I need to achieve?

Thank you.

View Complete Post

More Related Resource Links

Highlight text in a textbox

I have a textbox that could be 100 chars long. If I know the start & end positions of the text to highlight (via start & end position textboxes), how can I just highlight that portion of the characters in the textbox? 

How to make the textbox to highlight in C#

Hello All, I have to highlight the textbox when the user enters the Add button. The textbox is in nextpage In the next page which should be highlighted. I tried textbox1.Focus(). It will only highlight the textbox, but to enter the text in it, user should click the mouse on it. I also tried System.Windows.Input.Keyboard.Focus(textbox1); can you please help me to figure out the exact method. Thx, Shilpa

Highlight text in a dynamic textbox


 Hi, I have a dynamic textbox appearing in a gridview on the row editing function. I have the following code to set the focus tot he textbox:

GridView1.EditIndex = e.NewEditIndex

This works fine, but I would now also like to select the data in the textbox so the user does not have to select the text before typing, they can just type straight away.

I have been trying to use:

txtTargetAmount1.SelectionStart = 0
txtTargetAmount1.SelectionLength = txtTargetAmount1.Text.Length

but this does not work.

Any ideas?


MaskedEditExtender, text removed if you lose focus and set focus back on textbox


I have a MaskedEditExtender with Mask="(999) 999-9999".

Now my problem is, if someone goes into the textbox and enters


Then they leave the textbox, and then see that they forgot to enter the area code, if they go back in there to enter the area code, it starts overwritting the other numbers instead of just adding to them. 

Can't Set Textbox.Text Value with MaskedEditExtender


First, I am very new to ASP.NET and have only learned what I've learned by using Google and a couple books on ASP.NET  My methods may not be the best and I am not very good at it.  Second, I have a formview that opens up in Insert mode by default.  I have a datatable that I use in the code behind to retrieve certain values from a SQL database.  I want to populate a text box on this formview.  However, when I set the value of textbox.text, it doesn't show when the form is actually displayed.  I have placed the code to set it in both the Load event and Prerender event with no luck.  I have debugged the code and can see where the value is set.  If I remove the MaskedEditExtender from the text box, the value is populated.  I can't seem to figure out why it doesn't work with the MaskedEditExtender in place.  Any help would be greatly appreciated.  Code snippet below:

Code behind(I omitted the code for reading the datatable but can include it if necessary):

Dim admitTime As String
admitTime = ODIP1Table.Rows(0)("IP1ADMIT_TIME").ToString()
admitTimeTextBox = ERReportingFormView.FindControl("registrationTimeTextBoxInsert")
admitTimeTextBox.Text = admitTime.ToString()


Textbox with MaskedEditExtender(I omitted the remaining code for the f

Set contents of textbox when click to call phone number


So I have a text box


li class="textwidth">   
<label class="labelwidth" for="txtLine1">
    Phone #:</label>   
<asp:TextBox ID="txtPhoneNumber" runat="server" Width="202px" onkeydown="javascript:backspacerDOWN(this,event);" onkeyup="javascript:backspacerUP(this,event);" CssClass="inputwidth"></asp:TextBox>

When they click on this or when they click on something by this textbox I want it to call the phone number.

The ACTUAL phone number is filled in the pageload event:

If Not (SPPhone Is Nothing) Then
            Me.txtPhoneNumber.Text = SP.PhoneNumber

I know about the <a href="tel but I don't understand how I can implement it, since I don't know the phone number until the page actually loads.

Thanks for any and all help!

Textbox Editable GridView in ASP.NET

This article describes how I made a fully editable gridview in C# using ASP.NET 2. The idea is that the GridView looks and works like an Excel spreadsheet. You see all the cells in the table, and you can edit any of the cells you like, and they are automatically updated (i.e. saved to the database). This is very often how people expect data tables to work in web pages, and I've often seen people clicking in vain on un-editable gridview cells, somehow expecting to edit them, and not understanding that they need to click an Edit button at the end of the row.

jQuery: Highlight Gridview Rows with Checkbox

Im learning and experimenting with jQuery and ASP.NET. Below is a simple solution I created to highlight rows in a gridview by clicking on a checkbox next to the row.

Gridview setup:

Highlighting Rows with TextBox OnFocus

In another article I explained that how you can make the rows of the GridView control clickable and highlight them when they are clicked. In this article I will explain that how you can highlight the GridView rows when you focus on the TextBox which is contained inside the GridView control.

jQuery: Highlight Gridview Rows with Checkbox

Im learning and experimenting with jQuery and ASP.NET. Below is a simple solution I created to highlight rows in a gridview by clicking on a checkbox next to the row.

How to highlight datagrid or GridView row on mouse over?

This article will show how you can Ajax with GridView to display popup messages when mouse moves over certain column. In the demo project I have added first column as an image column with a help icon in it. This kind of implements a feature that if you want more information about the row you can move mouse over this icon, a asynchronous request is sent to server for data about that row and when call returns the returned message is show as a popup message.

Custom Editing Behavior for DataGridView TextBox Columns

For various reasons I'm using a DataGridView instead of a ListView, and while configuring the DataGridView to look like a ListView wasn't much of a problem, there's one thing that got on my nerves, which is the behavior of textbox cells in edit mode: It is much too easy to leave the edit mode accidentally, simply by pressing the cursor keys at the wrong time. For example when the text caret is positioned behind the last character of the textbox cell content, and you press the right arrow key

Editable Gridview with Textbox, CheckBox, Radio Button and DropDown List

This is an example of an editable gridview containing different ASP.NET controls. When user wants to edit values in gridview, she/he can use these controls to edit existing values in Gridview Edit Mode.

Using the Code

watermark textbox using Ajax control

This is pretty simple compared to jquery. Since we need refer a dll only. we dont want any script for this. we just include that reference into our website.

highlight string


i am looking for a function that takes two string parameters 

str1 = "hello how are you today mr john"

str2 = "how today"

and in return it shoud highlight the words "how" and "today".

Any ides? I prefer if its possible using reg expression...Thanks

How to take value of bound field of grid in a variable or in a textbox.


How to take value of bound field of grid in a variable or in a textbox.

 I m using this code in .aspx page for grid.

<asp:GridView ID="Grd_Mprocess" runat="server" AutoGenerateColumns="False"

                      Width="100%" AllowPaging="True"


                      AllowSorting="True" PageSize="5"  >

                 <RowStyle CssClass="odd" />


<asp:BoundField HeaderText="DOC_TYPE_PK" DataField="DOC_TYPE_PK"  Visible="true" >


  <asp:TemplateField HeaderText="DOC TYPE ID" Visible="true">  &nbs

Textbox in ItemTemplate inside Gridview, unable to get the value


Hi. I have a itemtemplate inside a gridview.

<asp:TemplateField HeaderText="Enter OTP">
                            <asp:Label ID="Label2" runat="server"
                                style="font-family: Arial, Helvetica, sans-serif; font-size: x-small"
                                Text="PIN Num:"></asp:Label>
                            &nbsp;<asp:TextBox ID="txtPIN" runat="server" Height="21px" Width="100px"></asp:TextBox>

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend