adjust text box size if text is too big to fit in its original size

 

Hi,

On mouseover of hypertext, I call function in javascript & print text in textbox. As shown following:

<a  href=""  onclick="home() >

 </a>

 

function home()
{
var TB=document.getElementById ("<%=txtbox.ClientID%>");
TB.value="HELLO THERE "
}

 

But if the text to be printed is too big to fit in text box, then text box size  (height, width)should get adjusted .

Is there any property of textbox to achieve this?

 


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
12/31/2008 7:47:54 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

14 Replies
810 Views

Similar Articles

[PageSpeed] 51

Try with this:

TB.style.width = "400px";

0
kipo
12/31/2008 7:57:41 AM

Hi,

Is it necessary to use Textbox? I mean If you can use Label then it will solve your problem. Another suggestion is that Instead of Textbox, You can go for multiline textbox. If length & Width of text get increased then you'll get a scrollbar inside.

So, my suggestion is either to use Label or Multiline Textbox.


Thanks and Regards,
Kinjan Shah,
MCAD
http://TricksForProgramming.BlogSpot.com
----------------------------------------------------
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved.
0
KinjanShah
12/31/2008 8:01:04 AM

KinjanShah:

Hi,

Is it necessary to use Textbox? I mean If you can use Label then it will solve your problem.

 

I dont want to use multiline textbox as it wud give ugly look. 

I think label should do. But when i used following code, i could not see any text on label. why so?

 

function home()
{
var lbl=document.getElementById ("<%=lbltext.ClientID%>");
lbl.value="HOME"
}


function new1()
{
var lbl=document.getElementById ("<%=lbltext.ClientID%>");
lbl.value="NEW"
}

 

 

 

 

 

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
               
                <%--<asp:TextBox  BorderStyle="None" BorderColor="white" ID="txtbox" runat="server" Height="176px" ReadOnly="True" Width="757px" ></asp:TextBox>--%>
                <asp:Label ID="lbltext" runat="server" ></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
        

 

 

 <div class="animatedtabs">
<ul>
<li><a  href=""  onclick="home();return false;" onmouseover="home()" ><span>Home</span></a></li>
<li> <a href="" ><span>CSS</span></a></li>
<li><a href="" onmouseover="new1()"  onclick="new1();return false;" ><span>New</span></a></li>

</ul>

</div>

 

 


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
12/31/2008 9:00:23 AM

Hi ,

Assign the text box width to 100%.  Check whether this works.

 

 

Regards

Suresh Kumar Goudampally

0
suresh_g_v2002
12/31/2008 9:04:41 AM

You can use multiline textbox without scrollbar

<asp:TextBox ID="TextBox1" runat="server" Text = "This is line one" TextMode = "MultiLine" Width="397px" style ="overflow:hidden " ></asp:TextBox>


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
12/31/2008 9:11:39 AM

closeguy2005:

KinjanShah:

Hi,

Is it necessary to use Textbox? I mean If you can use Label then it will solve your problem.

 

I dont want to use multiline textbox as it wud give ugly look. 

I think label should do. But when i used following code, i could not see any text on label. why so?

 

function home()
{
var lbl=document.getElementById ("<%=lbltext.ClientID%>");
lbl.value="HOME"
}


function new1()
{
var lbl=document.getElementById ("<%=lbltext.ClientID%>");
lbl.value="NEW"
}

 

 

 

 

 

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
               
                <%--<asp:TextBox  BorderStyle="None" BorderColor="white" ID="txtbox" runat="server" Height="176px" ReadOnly="True" Width="757px" ></asp:TextBox>--%>
                <asp:Label ID="lbltext" runat="server" ></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
        

 

 

 <div class="animatedtabs">
<ul>
<li><a  href=""  onclick="home();return false;" onmouseover="home()" ><span>Home</span></a></li>
<li> <a href="" ><span>CSS</span></a></li>
<li><a href="" onmouseover="new1()"  onclick="new1();return false;" ><span>New</span></a></li>

</ul>

</div>

 

 

 

Yes, Multiline Textbox will give ugly look.

 

Ok if you are using Label in JavaScript then you need to write "innerHTML" instead of "value"

So, write

lbl.innerHTML = "NEW"

lbl.innerHTML = "HOME"

This will solve your problem.

Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved.

 


Thanks and Regards,
Kinjan Shah,
MCAD
http://TricksForProgramming.BlogSpot.com
----------------------------------------------------
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved.
0
KinjanShah
12/31/2008 9:19:09 AM

Closeguy

Label gets converted to span And span does not have value property it has innerText Property

hence use

function new1()
{
var lbl=document.getElementById ("<%=lbltext.ClientID%>");
lbl.innerText="NEW"
}


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
12/31/2008 9:32:16 AM

closeguy2005:
I think label should do. But when i used following code, i could not see any text on label. why so?
 

 

closeguy2005:
lbl.value="NEW"

lbl.innerHTML="NEW";


We All move to our original place.
Don't forget.

Imran Baloch
0
imran_ku07
12/31/2008 9:32:42 AM

 

mudassarkhan:

Closeguy

Label gets converted to span And span does not have value property it has innerText Property

hence use

function new1()
{
var lbl=document.getElementById ("<%=lbltext.ClientID%>");
lbl.innerText="NEW"
}

 

Thanks all of you..

marked correct answer.

Also,  mudassarkhan thank you for the help. I did not mark your answer as Correct because innertext property does not work in either of IE & MOZILLA.

ALso did not try your other solution ( style:overflow)..thanks anyways

 














 

 


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
12/31/2008 9:50:37 AM

closeguy2005:

Also,  mudassarkhan thank you for the help. I did not mark your answer as Correct because innertext property does not work in either of IE & MOZILLA.

ALso did not try your other solution ( style:overflow)..thanks anyways

innerText works in IE check it Out. i dont know about Mozilla


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
12/31/2008 10:09:14 AM

Hi Closeguy2005,

instead of writing "innertext" you need to write "innerText". this should work.


Thanks and Regards,
Kinjan Shah,
MCAD
http://TricksForProgramming.BlogSpot.com
----------------------------------------------------
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved.
0
KinjanShah
12/31/2008 10:16:15 AM

 Hi,

innerText only works in IE not in FF,

for FF you can use textContent property

 

sample :

if(document.all)

{

 lbl.innerText = "hello World";

}

else

{

  lbl.textContent= "hello World";



Sincerely,
MOONCODER

Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question.
0
mooncoder
12/31/2008 10:40:52 AM

KinjanShah:

Hi Closeguy2005,

instead of writing "innertext" you need to write "innerText". this should work.

 

No need....innerHTML as specified by you works..

i was mentioning to mudassarkhan that innerText  does not work in FF because he doesn't know


Please Mark the post as "ANSWER" if it helps you
0
closeguy2005
1/1/2009 3:07:09 AM
Yes I am aware of it. but thought to let you know about it. Otherwise innerHTML will work fine.
Thanks and Regards,
Kinjan Shah,
MCAD
http://TricksForProgramming.BlogSpot.com
----------------------------------------------------
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved.
0
KinjanShah
1/1/2009 3:49:32 AM
Reply:

Similar Artilces:

Make text size independent of Browser's text size
How can I make sure that no matter what the user sets the text size in his or her browser, the actual size remains unaltered on a ASP.Net page? Thanks Sunilsun21170 Use absolute text sizes - e.g. size="10pt" or something like that. :)--Brian DesmondWindows Server MVP - Directory Serviceshttp://www.briandesmond.com Thanks. I got it. Sunilsun21170...

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin = window.open('foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script> &...

How to adjust the web form size with the user screen size?
Hi, I have a web form that when I display it in a 17” screen, the form limits are adjusted properly to the width screen size. But when I display it in other smaller screens, the web form limits exceeds the size of the current screen, and the horizontal scrollbar appears, which I don’ t want. How can I adjust my web form with all the possible user screen sizes so that the horizontal scrollbar never appears? Thank you, CesarCèsar I believe this is why some designers use a table (w/a width set to 100%), and have their forms set to use flowdesign. They place all of their controls w/...

Dynamically adjust TextBox size according to the size of text.
Can the ASP.NET TextBox control set to multiline be adjusted such that it displays the about of text it contains and takes up only that much space. Means, if it is databound and the column contains 10 lines, 10 lines are displayed. If 50 lines in the database, 50 lines are displayed and the vertical scrollbar will not be displayed. The textbox will automatically take as much space on the page as the size of the text.-----------------------------------------------Please click Mark as Answer if this helped. Hi, Use the TextBox Rows property to set the number of rows displayed in a...

how to change the font of some text in the text box to different size
hi all, I am developing web application. I have some text in text box. Now i want to change the font of some text to different size than the other lines in the text box. How can i do this. Can anybody help me regarding this. thanks in advance I think you should use some other Text Input control beacause it is not possible in text box. Try the Free text Box in the link below. http://freetextbox.com/default.aspx This will solve your problemMuhammad ShoaibSoftware Engineer,Lahore, Pakistanwww.heartofpakistan.com (U/C)--------------------------------Mark it as ANSWER if it Helps U ...

Limiting Text Size in a Web Form
Hello,   I want to display valiable length text strings in a limited space (known pixel width).   For example  "This is a very long string" would be limited to "This is a very..."   Are there any rendering helper functions to calculate the size of the text (considering font and style of course) in pixels, or to limit the displayed text?   Many thanks   Ofer   Hi There If the text is within say a text box then you can set the size of the text box to say 15 characters - then what to do is check the length of the text and then wriet a function w...

How to adjust the size of label control in the datalist, according to the size of its text?
Hello guys, I have a datalist with RepeatDirection="Horizontal" and RepeatLayout="table". I have a lable control in the data list. I want the layout of my data looks like data elements 1, data element 2,....... but I can not find a property that could adjust the width of the label control according to the length of the text. So far, my layout looks like data           ,      data element 1          element 2 Could some help   thanks ...

How do I block a user from entering text in a text box if they type text in another text box?
I have two text boxes, and want the user to complete one or the other.  How can I "grey out" one text box if a user starts typing in the other textbox?  Never make important decisions on a Monday! You can use the OnTextChanged event of the textboxes and write Javascript for both textboxes to disable the other textbox when the user starts to type in something in one textbox. The only problem with that is that once the user starts to type in something in one text box the other textbox gets disabled and locks up, so now the user HAS TO compulsarily type what he wants in th...

Can I change a treeview's text size depending on what my browser's text size is set to?
I'm using a treeview on a .net 2.0 page and all is working fine with it in Internet Explorer.  However if I go to View -->  Text Size --> Largest on my browser's menu, all the text on my page appears huge apart from the text in the treeview which remains the same size as it always was.  Is there a way to fix this so that this text will also increase in size? Many Thanks. Make sure the font size is not set in the control.  And use css to help moderate your pages look and feel. HTH,Joe JohnstonIf a picture is worth a 1000 words, a sample application ...

Check if the text box "text" has changed (RePost from web forms forum)
Greetings! How can i know if the "text" inside of a text box has changed? For example, I currently have this: if (txtMU.TextChanged()) { } But this does not work. The other idea I had was to assign the existing value of the text box to a string and then when the user click the save button I can create a conditional statement to compare the original string with the new string. However, I would like something more effective as I have like 12 text boxes to compare. Thanks, EduardoThanks,Please Mark this post as answered if it was helpful. Here is the easiest way that I have ...

VB .net Web Form will not get contents of Text Box
I have created a web form with text boxes that are bound to a DataSet/DataView.  I have created button to navigate up and down the recordset.  That all works fine. I need to have the ability to edit/add text in any of the boxes and then when clicking "Save" button, it would build an UPDATE query to send to the database. When the Save button is clicked, I have coded to DIM a string var (strSQL) to use to build the SQL command.  For some reason, it will only get the text from a text box if the data was pulled the database.  If I add/edit data, then the SQL command will ha...

Passing Text of a text box in child form to a label in parent form
Hi Elite People !! I have a parent form with a number of ASP Labels and Buttons. Each ASP Label has a ASP Button next to it. What I want to acheive is when you click the button, it should open a new window with a ASP multiline text box and a "save" button. User can enter the text in the text box and when they click the SAve button, the Text in the text box of the Child window should be displayed in the label on the parent form.  I am successfully able to do this when I have a Text Box in the Parent form, but my requirement is to use Labels on the Parent Form. I am ...

Size web form with size of screen
How i can resize my web form with the size of the screen of the client Other than width/height = 100%?Encosia - ASP.NET, AJAX, and more.Latest article: Using complex types to make calling services less… complex Check out Javascript's window.resizeTo(x,y) (scroll down). You can get screen size from screen.availWidth & availHeight Thanks....it works...

Bold Text For Selected text in Text Box
Hi EveryoneI have a small thing to do [at this time , very big for me]. I want to make some text string as bold which appears in a text box control for the web. It means some of the portion of the string will be bold and some will be in the normal font style. Can anyone suggest any idea to accomplish this task. [I know that we can set the font weight property for the whole text box and all the text appears in the selected font-weight]Any suggestions.BaberBaber SaeedSoftware EngineerPalmChip, Pakistan Toll Free: 0800-000-13 Ext:494Cell: 0300-6438634 Standard TextBox that comes with ASP.NET ...

Web resources about - adjust text box size if text is too big to fit in its original size - asp.net.web-forms

Viacom (original) - Wikipedia, the free encyclopedia
This article is about the original Viacom (founded 1971). For the current state of the company since 2006, see CBS Corporation . For the new ...

Wiggles reunite original members to reward first fans with pub gigs
While there won't be black skivvies instead of the customary red, yellow, blue and red tops, a planned pub tour by the original Wiggles lineup ...

Original pizza king Theo Kalogeracos returns to Leederville strip with Theo + Co
... a new pizzeria a few doors down, of course. But this is not a sorry saga about revenge or dough. Kalogeracos, who opened and has run the original ...

NVIDIA commits to Marshmallow update for Shield Tablet K1, original Shield Tablet
With the launch of the new Shield Tablet K1 and the swift move of the original Shield Tablet to end-of-life status, NVIDIA has stated that it ...

Is the original Acura NSX a perfect supercar?
... the first-generation NSX, exploring what made that car so good that the new one is still trying to live up to it. Continue reading Is the original ...

I Am the Avalanche's original lineup playing Brooklyn with Timeshares; The Movielife playing NJ in December ...
photo: The Movielife at Riot Fest Chicago 2015 (more by Rudy Rubio) The Movielife were supposed to play Starland Ballroom in June with Timeshares ...

Amazon's 'Man in the High Castle' TV series has made Philip K. Dick's original book a bestseller
New Amazon TV series "The Man in the High Castle" is driving new interest in the 1962 Philip K. Dick fantasy novel. In just days before the ...

This Kitten Version of All Eight Harry Potter Movies Might Be Better Than the Originals
Submitted by: (via The Pet Collective ) Tagged: Harry Potter , cute , Cats , Video Share on Facebook

Xbox One backwards compatibility for original Xbox games 'very challenging'
Engineering lead says "nothing's impossible," but it would be a significant challenge.

This Is The Original Taco Bell Building Being Relocated On The Back Of A Truck
... the fountainhead from which an empire of gorditas, chalupas, and Dorito-shelled tacos burst forth. As we reported earlier this week , the original ...

Resources last updated: 11/24/2015 10:51:02 PM