Programmatically change width of texbox?

  • Thread starter Thread starter Gandalf
  • Start date Start date
G

Gandalf

I thought this would be straightforward but it's not. How do I
programmatically reduce the width of a textbox by 20 pixels, say?

TextBox1.Width = TextBox1.Width - 20;

doesn't work.

Thanks in advance!

--
 
For that matter I could say:

TextBox1.Width=150;

which works, but that's not what I want.

--

Steve C. Orr said:
Try this code:

TextBox1.Attributes.Add("width", 150)
 
are you looking for this ?

this.TextBox1.Width = Unit.Pixel((int)TextBox1.Width.Value - 20) ;

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
It works but you don't want to use it? Would you prefer to use something
that doesn't work?
Well what is it that you want?
 
The width of a textbox is not accessible thru the attributes collection. You
need to test your code before posting it! ;-)
 
So now you're saying the code doesn't work?
You just said in your last message that it does work!
Make up your mind!
 
Your code doesn't work. Perhaps you should consider buying a book. I can
recommend a few if you like...

"Beginner's Guide to ASP.NET"
"ASP.NET for Dummies"


Those should get you started.

--
 
Gee, for a person who can't even figure out how to set the width of a
textbox you aren't very humble now are you?
If only you were as wise as Gandalf the Grey.
The next time you post a question I shall promptly ignore it.

Natty's code is great for some situations depending on what you are trying
to do, but it only works with IE. Mine is cross browser.

In case you care, here's the working version of the code that I meant to
post:

MyTextBox.Attributes.Add("style", "width:350px;")

I'd explain to you how it works, but you probably wouldn't understand
anyway.
 
Gandalf Hi,

I don’t think Steve is desert this kind of behavior, He just want to
help you. Actually I learn my suggested answer from him...

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
Steve C. Orr said:
Gee, for a person who can't even figure out how to set the width of a
textbox you aren't very humble now are you?
If only you were as wise as Gandalf the Grey.
The next time you post a question I shall promptly ignore it.

Natty's code is great for some situations depending on what you are trying
to do, but it only works with IE. Mine is cross browser.

In case you care, here's the working version of the code that I meant to
post:

It's amazing what you can come up with if you work for over 24 hours on a
problem. Well done Steve, you're a champ! No seriously, you are. Honestly.
Really.
 
Back
Top