.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 text in a textbox

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :ASP.Net
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? 

View Complete Post

More Related Resource Links

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?


Textbox text populated by Session Variable wont update into SQL with new text


Hi everyone, I have what I think is a weird issue. I send text from one page to another via Session Variable. When page 2 loads, the text box has the session text set, but if the user changes the text and clicks the button, the SQL database is update with the original session text. If I remove the redirect from the page 2 button_Click method, then, the page refreshes with the textbox reverting to the session text and thr SQLDataSource has the session text added to it.

Why would the button click cause the textbox refresh with the text from the pageLoad before updating the data source?


Partial Class _1
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Session("UpdateProd") = "Have some text here to send to a textbox on page 2"
    End Sub
End Class

Partial Class _2
    Inherits System.Web.UI.Page


Replace Text in textbox in word document using interop and asp.net

Hi all,  I'm trying to create a function to replace fields in a word document using asp.net. The fields are marked in the document using ###field### and I need to replace them with the data from the DB. The code I have works fine for the body of the word document but doesn't appear to work if the text is contained within a textbox, is there a way to correct this? Here's the code I am currently using Dim Contract as string Dim word As New Word.Application        Dim doc As Word.Document        Try            word.Documents.Open("c:\FYI.doc")            word.Visible = True             doc = word.ActiveDocument            Dim myStoryRange As Microsoft.Office.Interop.Word.Range            For Each myStoryRange In doc.StoryRanges                With myStoryRange.Find                    .Text = "###field###&quo

TextBox shows binding source text when window load, so why not with the ComboBox?

How can I get a ComboBox to show the binding source value when my window opens?  I have been searching all day for a solution to this, but cannot find anything.  So I have created a sample project to demonstrate my problem.  Below is a Vehicle class, very simple, two members Category and Make.  Category is an enumeration, Make is a string. namespace ComboExample { public class Vehicle { // Constants and enumerations public enum eCategory { Road, Air, Sea } // Attributes public eCategory Category { get; set; } public String Make { get; set; } // Construction public Vehicle(eCategory Category, String strMake) { this.Category = Category; this.Make = strMake; } } } Here is the C# for the MainWindow.  A new Vehicle object is created as a member.  In the constructor I set a data-provider in the XAML to this Vehicle object.  There is a button event for showing the values of the controls and objects so I can check the binding. namespace ComboExample { // Interaction logic for MainWindow.xaml public partial class MainWindow : Window { // Attributes Vehicle m_Car = new Vehicle(Vehicle.eCategory.Road, "BMW"); // Construction public MainWindow() { InitializeComponent(); // link data-p

Textbox in headertemplate gridview lost text in updatepanel

Hi everybody,I never post on this forum because since I write code in asp.net I always solve issues by finding solutions with other members who have the problem before me. But this time I don't know how to do...This is my problem : I have a gridview inside an updatepanel and i modified some headers in order to filter the collection. This worked but when my updatepanel is updating, my textbox for the filter clear the value (the text) and lost focus.Is there any solution ?This is my code : <asp:UpdatePanel ID="UpdatePanelOrders" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="btFilterClear" /> </Triggers> <ContentTemplate> <asp:GridView ID="OrdersView" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" ShowHeaderWhenEmpty="True" EnablePersistedSelection="True" PagerStyle-CssClass="pager" AlternatingRowStyle-CssClass="alter_row" SelectedRowStyle-CssClass="select_row" DataKeyNames="CustId,SalesOrders,CompCode,CustPO"> <Columns>

When I click on a TextBox the text moves a little bit for Vertical Alignment

I have a Grid of text boxes defined in the XAML using the following code:         <Border Grid.Row="2" Grid.Column="11" Style="{StaticResource BorderStyleContent}" >             <TextBox Text="-15.11" Style="{StaticResource EditableTextBox}"/>         </Border> The styles are defined below:         <Style x:Key="BorderStyleContent" TargetType="Border">             <Setter Property="BorderBrush" Value="Black"/>             <Setter Property="BorderThickness" Value="1"/>             <Setter Property="Padding" Value="2"/>             <Setter Property="SnapsToDevicePixels" Value="True"/>         </Style>         <Style x:Key="EditableTextBox" TargetType="TextBox">         &nb

Textbox Text Property

I am new to VB and I have read that if I don't explicity cast variable types it will eat up performance. I have been casting certain objects, such as values from data readers, but I was wondering if the object has a property that says it is a string, like the textbox "Text" property, if I need to still cast that as a string.   Right now my code says "txtSearch.Text" but should I be using "txtSearch.Text.ToString()"?   Thanks in advance for the help!

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

Unable to fetch text from a textbox with numeric up-down extender

I have a textbox with numeric updown extender.I want the text of the textbox.I have written code in code file is String a=txtHour.Text//  Source FIle COde<asp:TextBox ID="txtHour" runat="server" ReadOnly="True" Width="45"                     Style="text-align:center" Height="20px"></asp:TextBox>                                       <cc1:NumericUpDownExtender ID="NumericUpDownExtenderHr" runat="server"                     Enabled="True"                     Minimum="00" Maximum="23"                    TargetControlID="txtHour" Width="40">                </cc1:NumericUpDownExtender>

how to print rich textBox Formatted text

Hi,  I have some text in rich text box format in a table.The data is like  {\rtf1\ansi\ansicpg1252\deff0\deflang16393{\fonttbl{\f0\fnil\fcharset0 NSimSun;}{\f1\fnil\fcharset0 Microsoft Tai Le;}{\f2\fnil\fcharset0 MingLiU_HKSCS;}{\f3\fnil\fcharset0 Palace Script MT;}{\f4\fnil\fcharset0 Microsoft Sans Serif;}} {\colortbl ;\red0\green192\blue0;} \viewkind4\uc1\pard\cf1\b\f0\fs44 hello hi\par \lang1033\f1 hi i am fine\par \f2 about u?\lang16393\b0\i\f3\par \par \par \cf0\i0\f4\fs17\par }  Now,I want to print the data in corresponding format.can u please Help me.....

How to: textbox text should show only the last part of the string

Hi, I have a textbox that shows info. (filename) When the filename is smaller than the width of the textbox all is fine, but when the filename is longer, i would like to show the last part of the filename in stead of the first part (default). Is this possible?

Wish to stop user from entering text in a textbox

I want to stop user from entering stuff in a textbox. But if I use Readonly then for some reason I can't get the information to the database. Ant ideas? 

How can I use a textbox text as a parameter to a hyperlink


I am using a hyperlink to link to another web form page. I am not able to pass the text of textbox as a parameter.

Thanks In advance, 

Highlight a treeviewitem Text on click of Checkbox in WPF



 I want to highlight the text of checked treeviewitem of a treeview in wpf.

Treeview contains check boxes for all the items. So when a user checks a treeviewitem. the text associated with it should be highlighted. Right now I am doing this on treeview checked method. Is there any other way. Like doing it by triggers.

Text selection in textbox on mouse over


I am having a Textbox and want to selcted text with perticular format on mouse over.

So if my text in textbox is "This person <<PersonName>> has a good experience of <<Year>> in <<Technology>>". Now if I put my mouse over <<PersonName>> or <<Year>> or <<Technology>>, only this text (<<PersonName>>, etc) should be highlighted. 

How can I start implementing this as I know Textbox in WPF/Silverlight doesn't provide this behavior.

problem in retriving text from a textbox


<asp:DataList ID="DataList1" runat="server" DataSourceID="ObjectDataSource1"
Height="132px" style="font-size: medium; font-family: Georgia; color: #006600"
Width="307px" DataKeyField="scrapsndrcod"
<b> <%#Eval("nam") %>:</b>
<%#Eval("scrapmsg") %>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /> &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CommandName="rply" >Reply</asp:LinkButton>
&nbsp;<asp:LinkButton ID="LinkButton1" runat="server" CommandName="delete" CommandArgument='<%#Eval("scrapcod") %>'>delete</asp:LinkButton>
<asp:Panel ID="Panel1" runat="server" Visible="false">
<asp:TextBox ID="TextBox1" TextMode="MultiLine" runat="server"></asp:Tex

Can a textbox text be used as a parameter for a where clause


 I was wondering if there is a better way than what I am doing, if I want the text entered in the textbox to be the parameter of a where clause. I want to be able to display the records throught the gridview.




    <form id="form1" runat="server">
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Get_Details" />
            <asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource2">
  <asp:AccessDataSource ID="AccessDataSource2" runat="server"
     SelectCommand=  "SELECT PONumber,PartNumber,QtyOrdered,Units,QtyReceived,Description,UnitCost,ExtCost,ItemNote from ASPtbPOItem where PONumber=@TextBox1.Text">
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