Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.28/5 (4 votes)
See more:
in textbox i want to enter data from right side

like textbox in calculator
Posted
Updated 17-Jan-17 2:24am

XML
<style>
        .aligntext
        {
            text-align:right;
            }
    </style>



xml><asp:TextBox

 
Share this answer
 
v2
Comments
Manfred Rudolf Bihy 7-Jun-11 10:32am    
CSS is the definitely the right choice! 5+
Coding C# 7-Jun-11 10:35am    
Thanks Manfred :)
Sergey Alexandrovich Kryukov 7-Jun-11 14:59pm    
Sorry, this is a big mistake. text-align is merely align, not direction. I just had to vote 1.
Please see my answer for correct CSS.

OOPs! My mistake! I revoted - a 5.
--SA
C#
textBox1.TextAlign = HorizontalAlignment.Right
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Jun-11 15:00pm    
Sorry, this is a big mistake. text-align is merely align, not direction. I just had to vote 1.
Please see my answer for correct CSS.
--SA
S Houghtelin 7-Jun-11 15:20pm    
OP: "like textbox in calculator" He has not indicated he was looking for language formatting which is not "like textbox in calculator"

Before posting code, to assure accuracy I will test the code prior to posting, this method works in my C#, the text behaved like "like textbox in calculator"

Perhaps kumar from vijayawada could elaborate on this, but I'm not sure this warranted 1 voting everyone who genuinely attempted to help. These were not intended to be mean spirited answers.
Sergey Alexandrovich Kryukov 7-Jun-11 18:05pm    
I already know -- will fix it. I've been mislead by the answer by Manfred but his is of course my fault.
Thank you for correcting me.
--SA
S Houghtelin 7-Jun-11 18:35pm    
Thank you for having the guts to admit a mistake, and for the vote correction.

Kind Regards
No guarantees, but you might be able to use CSS:

Creat a class:

.rightText
{
    text-align:right;
}


and then set the CSSClass attribute to that class in the ASPX file.

<asp:TextBox CSSClass="rightText">
 
Share this answer
 
v2
Comments
Manfred Rudolf Bihy 7-Jun-11 10:33am    
As with Coding C#'s answer: 5+
CSS is the way to go.
Sergey Alexandrovich Kryukov 7-Jun-11 15:00pm    
Sorry, this is a big mistake. text-align is merely align, not direction. I just had to vote 1.
Please see my answer for correct CSS.
--SA
#realJSOP 7-Jun-11 17:48pm    
look at the question again. It says "like a calculator". That means the text is still in the same order it was typed, only "like a calculator", it's right-aligned.
Sergey Alexandrovich Kryukov 7-Jun-11 18:04pm    
Agree. I've been mislead by the answer of Manfred on RTL, but this is my fault of course. I'll remove my answer and re-vote everywhere.
--SA
#realJSOP 7-Jun-11 18:00pm    
I just tested it (couldn't test it at work). It works just "like a calculator". When you click the textbox, the caret is positioned at the right side of the control, and as you type, the characters move to the left - "like a calculator". I think you should change your vote to a 5 because my solution does, in fact, do what the OP described.
Set text box align property to right like here[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Jun-11 15:01pm    
Sorry, this is a big mistake. text-align is merely align, not direction. I just had to vote 1.
Please see my answer for correct CSS.

OOPs! My mistake! I revoted - a 5.
--SA
In C#

Select the TextBox -->
Goto Properties window -->
Select TextAlign --> Set the value to Right.


In ASP.NET

<br />
    <style><br />
        .alignToRight<br />
        {<br />
            text-align:right;<br />
        }<br />
    </style><br />
<br />



Regards!!!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Jun-11 15:01pm    
Sorry, this is a big mistake. text-align is merely align, not direction. I just had to vote 1.
Please see my answer for correct CSS.

OOPs! My mistake! I revoted - a 5.
--SA
Use the direction attribute dir and set it to "RTL". See here: http://msdn.microsoft.com/en-us/library/twe16yc2(v=VS.100).aspx[^].

Maybe you are more into this though: style="text-align: right;". Also see here: http://forums.asp.net/t/900887.aspx/1[^].

Cheers!

-MRB
 
Share this answer
 
v2
Comments
ambarishtv 7-Jun-11 10:25am    
answer +5
Manfred Rudolf Bihy 7-Jun-11 10:32am    
Thanks! :)
Uday P.Singh 7-Jun-11 13:22pm    
good answer my 5
Sergey Alexandrovich Kryukov 7-Jun-11 14:58pm    
Correct - partially. My 4. Your comments on CSS are wrong! Other answers are incorrect as text-align is not it. This is merely the alignment, not direction.
Please see my answer for correct CSS.

Using RTL is incorrect. John brought to my attention -- it's alignment. I removed my answer.
--SA
Usually use English.
That goes from the right side.

If you use other non-european languages, they are from the left.
 
Share this answer
 
This may also help
.textbox_ClassName {text-align:end;}
or
.textbox_ClassName {text-align:right;}
or
.textbox_ClassName {text-align-last:end;}
or
.textbox_ClassName{text-align-last:right;}
or
.textbox_ClassName {direction:RTL;}
 
Share this answer
 
v3
Comments
[no name] 17-Jan-17 8:33am    
There is no reason at all for you to resurrect SIX year old already answered questions.
I think this may help you

<asp:TextBox ID="TextBox1" runat="server" CssClass="ltor">


and css:

.ltor {direction:rtl;}
 
Share this answer
 
Comments
[no name] 17-Jan-17 8:33am    
There is no reason at all for you to answer SIX year old already answered questions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900