Programmatically change width of texbox?

Discussion in 'ASP .Net' started by Gandalf, Jul 30, 2003.

  1. Gandalf

    Gandalf Guest

    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!

    --
     
    Gandalf, Jul 30, 2003
    #1
    1. Advertising

  2. Try this code:

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

    --
    I hope this helps,
    Steve C. Orr, MCSD
    http://Steve.Orr.net


    "Gandalf" <> wrote in message
    news:...
    > 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!
    >
    > --
    >
    >
    >
     
    Steve C. Orr, MCSD, Jul 30, 2003
    #2
    1. Advertising

  3. Gandalf

    Gandalf Guest

    For that matter I could say:

    TextBox1.Width=150;

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

    --

    "Steve C. Orr, MCSD" <> wrote in message
    news:...
    > Try this code:
    >
    > TextBox1.Attributes.Add("width", 150)
    >
    > --
    > I hope this helps,
    > Steve C. Orr, MCSD
    > http://Steve.Orr.net
    >
    >
    > "Gandalf" <> wrote in message
    > news:...
    > > 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!
    > >
    > > --
    > >
    > >
    > >

    >
    >
     
    Gandalf, Jul 30, 2003
    #3
  4. Gandalf

    Natty Gur Guest

    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!
     
    Natty Gur, Jul 30, 2003
    #4
  5. 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" <> wrote in message
    news:...
    > For that matter I could say:
    >
    > TextBox1.Width=150;
    >
    > which works, but that's not what I want.
     
    Steve C. Orr, MCSD, Jul 30, 2003
    #5
  6. Gandalf

    John Smith Guest

    Thanks Natty, that's what I want.

    "Natty Gur" <> wrote in message
    news:...
    > 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!
     
    John Smith, Jul 30, 2003
    #6
  7. Gandalf

    John Smith Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > For that matter I could say:
    > >
    > > TextBox1.Width=150;
    > >
    > > which works, but that's not what I want.

    >
    >
     
    John Smith, Jul 30, 2003
    #7
  8. 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" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > news:...
    > > > For that matter I could say:
    > > >
    > > > TextBox1.Width=150;
    > > >
    > > > which works, but that's not what I want.

    > >
    > >

    >
    >
     
    Steve C. Orr, MCSD, Jul 30, 2003
    #8
  9. Gandalf

    Gandalf Guest

    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" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:%...
    > > 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" <> wrote in message
    > > news:...
    > > > 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" <> wrote in message
    > > > news:...
    > > > > For that matter I could say:
    > > > >
    > > > > TextBox1.Width=150;
    > > > >
    > > > > which works, but that's not what I want.
    > > >
    > > >

    > >
    > >

    >
    >
     
    Gandalf, Jul 31, 2003
    #9
  10. Gandalf

    Gandalf Guest

    Note to Steve C. Orr, MCSD!!...

    See answer below. It works.

    --

    "Natty Gur" <> wrote in message
    news:...
    > 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!
     
    Gandalf, Jul 31, 2003
    #10
  11. 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" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:%...
    > > 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" <> wrote in message
    > > news:%...
    > > > 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" <> wrote in message
    > > > news:...
    > > > > 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" <> wrote in message
    > > > > news:...
    > > > > > For that matter I could say:
    > > > > >
    > > > > > TextBox1.Width=150;
    > > > > >
    > > > > > which works, but that's not what I want.
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Steve C. Orr, MCSD, Jul 31, 2003
    #11
  12. Gandalf

    Natty Gur Guest

    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!
     
    Natty Gur, Jul 31, 2003
    #12
  13. Gandalf

    Gandalf Guest

    "Steve C. Orr, MCSD" <> wrote in message
    news:...
    > 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.
     
    Gandalf, Aug 1, 2003
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David

    width of texbox in editItem

    David, Jan 25, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    373
    David
    Jan 25, 2005
  2. AndrewF
    Replies:
    1
    Views:
    785
    Bruce Barker
    Oct 10, 2005
  3. K Schleyer

    Can I programmatically change width/height of column in edit mode

    K Schleyer, Jan 16, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    159
    K Schleyer
    Jan 16, 2004
  4. Michael Haren via .NET 247

    cannot change value of texbox w/in datagrid after first bind

    Michael Haren via .NET 247, Sep 8, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    121
    Michael Haren via .NET 247
    Sep 8, 2004
  5. Replies:
    0
    Views:
    117
Loading...

Share This Page