Programmatically change width of texbox?

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!

--
 
G

Gandalf

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)
 
N

Natty Gur

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
 
S

Steve C. Orr, MCSD

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?
 
J

John Smith

The width of a textbox is not accessible thru the attributes collection. You
need to test your code before posting it! ;-)
 
S

Steve C. Orr, MCSD

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!
 
G

Gandalf

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.

--
 
S

Steve C. Orr, MCSD

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.
 
N

Natty Gur

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
 
G

Gandalf

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top