Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comapring two <asp:TextBox> lines

Status
Not open for further replies.

tsisher

Programmer
Sep 14, 2004
36
0
0
GB
Is it possible to do this ?

Let me explain this.
// aspx
<asp:TextBox runat="server" ID="txtOld" TextMode="MultiLine" Columns="70" Rows="30" Width="425px" />
<asp:TextBox runat="server" ID="txtNew" TextMode="MultiLine" Columns="70" Rows="30" Width="425px" />
<asp:Button Text="Compare" runat="server" ID="btnCompare" OnClick="btnCompare_Click" />

// c#
I have two string

string strOld = "This a line 1\nThis is going to be line 2\rThis is going to be line 3\rThis is line 4";
string strNew = "This a line 1\nThis text is changed here going to be line 2\rThis is going to be line 3\rThis is changed line 4";

Please note that these strings have \n and \r in it.

When form loads, I do something like this
if (!IsPostBack)
{
txtOld.Text = strOld;
txtNew.Text = strNew;
}
Web browser automatically splits the strings and align nicely in the Text box like this

txtOld TextBox renders like this

This a line 1
This is going to be line 2
This is going to be line 3
This is line 4

txtNew TextBox renders like this

This a line 1
This text is changed here going to be line 2
This is going to be line 3
This is changed line 4

Now when hit compare button, I need to mark the lines and change the color of the lines in the text box which are different,

for example
Line 2 and line 4 in the above example.
I may be able to compare the strings but how do I mark and change color of the lines in the text box.
Please advice.

Any new ideas. Looking forward to it.

Thanks




 
I think you would be better off doing this client side using javascript rather than posting back to the server. You would also struggle to apply any colour formatting to the text within a textarea without using client scripting.

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top