Programmatically change width of texbox?

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

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

    --



    Gandalf Guest

  2. Similar Questions and Discussions

    1. Programmatically setting 100% width
      Is there a way to set a width of 100% for dynamically created components? ...
    2. Programmatically change iis rights
      Hi, Is it possible to programmatically (c# aspnet) change IIS rights on a file or a directory (allow write access on xml files, deny download...
    3. cannot change value of texbox w/in datagrid after first bind
      I have a datagrid with the columns defined in the aspx <columns> <asp:TemplateColumn HeaderText="Hours"...
    4. Can I programmatically change width/height of column in edit mode
      I have six bound columns. When I click Edit and go into edit mode, those six columns widths expand and force the browser to have a horizontal...
    5. How do I change the DataGrid column order programmatically?
      I use a single datagrid to load several different types of data depending upon some user driven criteria. The AutoGenerateColumns property for the...
  3. #2

    Default Re: Programmatically change width of texbox?

    Try this code:

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

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


    "Gandalf" <gandalf@sauron.com> wrote in message
    news:OhZfUjiVDHA.1748@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!
    >
    > --
    >
    >
    >

    Steve C. Orr, MCSD Guest

  4. #3

    Default Re: Programmatically change width of texbox?

    For that matter I could say:

    TextBox1.Width=150;

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

    --

    "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
    news:uLVzw1iVDHA.1560@TK2MSFTNGP11.phx.gbl...
    > Try this code:
    >
    > TextBox1.Attributes.Add("width", 150)
    >
    > --
    > I hope this helps,
    > Steve C. Orr, MCSD
    > [url]http://Steve.Orr.net[/url]
    >
    >
    > "Gandalf" <gandalf@sauron.com> wrote in message
    > news:OhZfUjiVDHA.1748@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!
    > >
    > > --
    > >
    > >
    > >
    >
    >

    Gandalf Guest

  5. #4

    Default Re: Programmatically change width of texbox?

    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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  6. #5

    Default Re: Programmatically change width of texbox?

    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" <gandalf@sauron.com> wrote in message
    news:eIWyVzjVDHA.1676@TK2MSFTNGP10.phx.gbl...
    > For that matter I could say:
    >
    > TextBox1.Width=150;
    >
    > which works, but that's not what I want.

    Steve C. Orr, MCSD Guest

  7. #6

    Default Re: Programmatically change width of texbox?

    Thanks Natty, that's what I want.

    "Natty Gur" <natty@dao2com.com> wrote in message
    news:OQkjPukVDHA.2328@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 [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    John Smith Guest

  8. #7

    Default Re: Programmatically change width of texbox?

    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" <Steve@Orr.net> wrote in message
    news:uunoxWmVDHA.424@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" <gandalf@sauron.com> wrote in message
    > news:eIWyVzjVDHA.1676@TK2MSFTNGP10.phx.gbl...
    > > For that matter I could say:
    > >
    > > TextBox1.Width=150;
    > >
    > > which works, but that's not what I want.
    >
    >

    John Smith Guest

  9. #8

    Default Re: Programmatically change width of texbox?

    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" <JSmith@Phoney.com> wrote in message
    news:%23FZyAipVDHA.2228@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" <Steve@Orr.net> wrote in message
    > news:uunoxWmVDHA.424@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" <gandalf@sauron.com> wrote in message
    > > news:eIWyVzjVDHA.1676@TK2MSFTNGP10.phx.gbl...
    > > > For that matter I could say:
    > > >
    > > > TextBox1.Width=150;
    > > >
    > > > which works, but that's not what I want.
    > >
    > >
    >
    >

    Steve C. Orr, MCSD Guest

  10. #9

    Default Re: Programmatically change width of texbox?

    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" <Steve@Orr.net> wrote in message
    news:%23lHJ8rsVDHA.3220@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" <JSmith@Phoney.com> wrote in message
    > news:%23FZyAipVDHA.2228@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" <Steve@Orr.net> wrote in message
    > > news:uunoxWmVDHA.424@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" <gandalf@sauron.com> wrote in message
    > > > news:eIWyVzjVDHA.1676@TK2MSFTNGP10.phx.gbl...
    > > > > For that matter I could say:
    > > > >
    > > > > TextBox1.Width=150;
    > > > >
    > > > > which works, but that's not what I want.
    > > >
    > > >
    > >
    > >
    >
    >

    Gandalf Guest

  11. #10

    Default Re: Programmatically change width of texbox?

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

    See answer below. It works.

    --

    "Natty Gur" <natty@dao2com.com> wrote in message
    news:OQkjPukVDHA.2328@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 [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Gandalf Guest

  12. #11

    Default Re: Programmatically change width of texbox?

    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
    [url]http://Steve.Orr.net[/url]


    "Gandalf" <gandalf@sauron.com> wrote in message
    news:%23HCp47uVDHA.1984@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" <Steve@Orr.net> wrote in message
    > news:%23lHJ8rsVDHA.3220@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" <JSmith@Phoney.com> wrote in message
    > > news:%23FZyAipVDHA.2228@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" <Steve@Orr.net> wrote in message
    > > > news:uunoxWmVDHA.424@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" <gandalf@sauron.com> wrote in message
    > > > > news:eIWyVzjVDHA.1676@TK2MSFTNGP10.phx.gbl...
    > > > > > For that matter I could say:
    > > > > >
    > > > > > TextBox1.Width=150;
    > > > > >
    > > > > > which works, but that's not what I want.
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Steve C. Orr, MCSD Guest

  13. #12

    Default Re: Programmatically change width of texbox?

    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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  14. #13

    Default Re: Programmatically change width of texbox?

    "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
    news:OqanDCxVDHA.208@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.


    Gandalf Guest

  15. #14

    Default Re: Programmatically change width of texbox?

    Re: Programmatically change width of texbox
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139