473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Programmatically change width of texbox?

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!

--

Nov 17 '05 #1
12 6627
Try this code:

TextBox1.Attributes.Add("width", 150)

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Gandalf" <ga*****@sauron.com> wrote in message
news:Oh**************@TK2MSFTNGP12.phx.gbl...
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!

--

Nov 17 '05 #2
For that matter I could say:

TextBox1.Width=150;

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

--

"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:uL**************@TK2MSFTNGP11.phx.gbl...
Try this code:

TextBox1.Attributes.Add("width", 150)

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Gandalf" <ga*****@sauron.com> wrote in message
news:Oh**************@TK2MSFTNGP12.phx.gbl...
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!

--


Nov 17 '05 #3
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #4
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?
"Gandalf" <ga*****@sauron.com> wrote in message
news:eI**************@TK2MSFTNGP10.phx.gbl...
For that matter I could say:

TextBox1.Width=150;

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

Nov 17 '05 #5
Thanks Natty, that's what I want.

"Natty Gur" <na***@dao2com.com> wrote in message
news:OQ**************@TK2MSFTNGP12.phx.gbl...
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #6
The width of a textbox is not accessible thru the attributes collection. You
need to test your code before posting it! ;-)

"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:uu*************@TK2MSFTNGP11.phx.gbl...
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?
"Gandalf" <ga*****@sauron.com> wrote in message
news:eI**************@TK2MSFTNGP10.phx.gbl...
For that matter I could say:

TextBox1.Width=150;

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


Nov 17 '05 #7
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!
"John Smith" <JS****@Phoney.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
The width of a textbox is not accessible thru the attributes collection. You need to test your code before posting it! ;-)

"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:uu*************@TK2MSFTNGP11.phx.gbl...
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?
"Gandalf" <ga*****@sauron.com> wrote in message
news:eI**************@TK2MSFTNGP10.phx.gbl...
For that matter I could say:

TextBox1.Width=150;

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



Nov 17 '05 #8
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.

--

"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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!
"John Smith" <JS****@Phoney.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
The width of a textbox is not accessible thru the attributes collection.

You
need to test your code before posting it! ;-)

"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:uu*************@TK2MSFTNGP11.phx.gbl...
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?
"Gandalf" <ga*****@sauron.com> wrote in message
news:eI**************@TK2MSFTNGP10.phx.gbl...
> For that matter I could say:
>
> TextBox1.Width=150;
>
> which works, but that's not what I want.



Nov 17 '05 #9
Note to Steve C. Orr, MCSD!!...

See answer below. It works.

--

"Natty Gur" <na***@dao2com.com> wrote in message
news:OQ**************@TK2MSFTNGP12.phx.gbl...
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #10
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.

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Gandalf" <ga*****@sauron.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

--

"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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!
"John Smith" <JS****@Phoney.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
The width of a textbox is not accessible thru the attributes
collection. You
need to test your code before posting it! ;-)

"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:uu*************@TK2MSFTNGP11.phx.gbl...
> 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?
>
>
> "Gandalf" <ga*****@sauron.com> wrote in message
> news:eI**************@TK2MSFTNGP10.phx.gbl...
> > For that matter I could say:
> >
> > TextBox1.Width=150;
> >
> > which works, but that's not what I want.
>
>



Nov 17 '05 #11
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #12
"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:Oq*************@tk2msftngp13.phx.gbl...
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.
Nov 17 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Carlo Marchesoni | last post by:
From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a button's event in A.aspx to be fired. I guess the only...
1
by: Billy Cormic | last post by:
Hello, Is there a way to set the width of a column in a datagrid? Does it have anything to do with Text Formatting String texbox in the Columns portion of the properties for the datagrid? ...
0
by: David | last post by:
How can I adjust the width of the textbox in editItem? Thanks
1
by: Michael via .NET 247 | last post by:
I have a datagrid with the columns defined in the aspx <columns> <asp:TemplateColumn HeaderText="Hours" ItemStyle-Width="1%"ItemStyle-HorizontalAlign="Center"> <ItemTemplate> <asp:TextBox...
6
by: Marc Robitaille | last post by:
Hello, Hello, I developed a UserControl. It has funny behavior. It is composed of three controls. A texbox, a combobox and a button. There are three properties to indicate the visibility of...
0
by: Cas | last post by:
Hi, I want to create a InsertItemTemplate in a detailsview (only insertmode)programmatically. I first defined a Template, then i tried to create within that templatefield a InsertItemTemplate...
0
by: Cas | last post by:
Hi, I want to create a InsertItemTemplate in a detailsview (only insertmode)programmatically. I first defined a Template, then i tried to create within that templatefield a InsertItemTemplate...
0
by: Amir Alilou | last post by:
hi I want to change the size of paper prorammatically in my code. but when i do it my printer paper size do not change. please help me with sample.(VB.NET 2003) Public Sub Print_It() Try Try...
0
by: veera venkata | last post by:
hi i am using the following code to provide the zoom,scroll for a image. but this code is working individually either scrolling or zooming. <div onmousemove=zoom_move(event);...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.