Render method?

Discussion in 'ASP .Net Web Controls' started by Karl, Mar 30, 2005.

  1. Karl

    Karl Guest

    I'm using Lutz Reoder's .NET Reflector program to browse the source code
    for System.Web.UI.WebControls.TextBox.


    Looking at this class's Render() method, I had expected to see code that
    would actually draw a textbox. No such luck.

    1) What code does draw the textbox?

    2) What's a HtmlTextWriter? (that's the parameter to the TextBox
    Render() method.)


    Ultimately, what I would like to do is create a TextBox control that
    keeps the insertion point flush right in the text box. Then, as the text
    is entered, the insertion point remains stationary, and the text moves
    to the left as new characters are inserted.

    Can this be done?

    Any pointers to get me started?

    Can I inherit from TextBox? Or to I have to completely roll my own?
     
    Karl, Mar 30, 2005
    #1
    1. Advertising

  2. Karl

    Brock Allen Guest

    > Looking at this class's Render() method, I had expected to see code
    > that would actually draw a textbox. No such luck.
    >
    > 1) What code does draw the textbox?


    Of course it does! But it uses some other code to help ;)

    TextBox is using the WebControl's base class to help render out the <input>
    tag. I think the insight comes from the answer to your next question.

    > 2) What's a HtmlTextWriter? (that's the parameter to the TextBox
    > Render() method.)


    HtmlTextWriter is a fancy wrapper on top of the Response object and its primary
    purpose is to abstract style attributes so that you don't have to write different
    code for different versions of HTML (like 3.2, 4.0, cHTML, XHTML, etc). So
    there are a ton of APIs on it to allow you to express the logical styles
    and it deals with the details of emitting the correct HTML.

    > I'm using Lutz Reoder's .NET Reflector program to browse the source
    > code for System.Web.UI.WebControls.TextBox.


    BTW, keep this up! This is how you'll learn how the innards of ASP.NET work.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen
     
    Brock Allen, Mar 30, 2005
    #2
    1. Advertising

  3. You can inherit and extend the standard textbox.
    Here is an example:
    http://steveorr.net/articles/InheritAndExtend.aspx

    However, I'm not sure if you'll be able to accomplish your particular goal
    by inheriting the textbox. If it's possible, it will take some fancy
    Javascript.
    Otherwise you may need to fake a textbox with a div and some fancy
    Javascript.
    You might be able to use a 3rd party textbox control that uses a technique
    like this already, such as one of these:
    http://steveorr.net/freecontrols/textboxes.aspx

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



    "Karl" <-grove.com> wrote in message
    news:%...
    > I'm using Lutz Reoder's .NET Reflector program to browse the source code
    > for System.Web.UI.WebControls.TextBox.
    >
    >
    > Looking at this class's Render() method, I had expected to see code that
    > would actually draw a textbox. No such luck.
    >
    > 1) What code does draw the textbox?
    >
    > 2) What's a HtmlTextWriter? (that's the parameter to the TextBox Render()
    > method.)
    >
    >
    > Ultimately, what I would like to do is create a TextBox control that keeps
    > the insertion point flush right in the text box. Then, as the text is
    > entered, the insertion point remains stationary, and the text moves to the
    > left as new characters are inserted.
    >
    > Can this be done?
    >
    > Any pointers to get me started?
    >
    > Can I inherit from TextBox? Or to I have to completely roll my own?
     
    Steve C. Orr [MVP, MCSD], Mar 30, 2005
    #3
  4. Karl

    Karl Guest

    Hi Steve,

    I don't know if you ran into this before or not. But I tried your
    numeric textbox and it seems that the javascript does not work in
    FireFox. That is, I can type any character I please. IE worked just fine.

    Any suggestions as to what I might have to do to rectify this? (I
    doubled checked, Javascript is enabled.) I've copied the source of the
    page below in case you see anything obvious.

    Oh, one other thing. :) Even in IE, the user, if they type a cursor
    key, the cursor moves. Do you know why the browswer still responds to a
    cursorkey stroke? It looks to me as if the Javascript should prevent
    that as well.

    Thanks,
    Karl


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema"
    content="http://schemas.microsoft.com/intellisense/ie5">
    <LINK REL="stylesheet" TYPE="text/css" HREF="StyleSheet1.css">

    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form name="Form1" method="post" action="WebForm1.aspx" id="Form1">
    <input type="hidden" name="__VIEWSTATE"
    value="dDwtMTExMzYxMDEzOTt0PDtsPGk8MT47PjtsPHQ8O2w8aTw1Pjs+O2w8dDxwPDtwPGw8b25LZXlQcmVzczs+O2w8VmFsaWRhdGVOdW1lcmljKCk7Pj4+Ozs+Oz4+Oz4+Oz4VkqDNHdqjFodNfkCACgw0HXMbWQ=="
    />
    <script language=javascript>function ValidateNumeric(){var keyCode =
    window.event.keyCode;if (keyCode > 57 || keyCode <
    48)window.event.returnValue = false;}</script>


    <input name="TextBox1" type="text" id="TextBox1" style="Z-INDEX: 101;
    LEFT: 344px; POSITION: absolute; TOP: 88px" />
    <input name="TextBox2" type="text" id="TextBox2" style="Z-INDEX: 102;
    LEFT: 344px; POSITION: absolute; TOP: 136px" />
    <input name="NumericTextbox1" type="text" id="NumericTextbox1"
    onKeyPress="ValidateNumeric()" style="Z-INDEX: 103; LEFT: 352px;
    POSITION: absolute; TOP: 192px" />

    </form>
    </body>
    </HTML>




    Steve C. Orr [MVP, MCSD] wrote:
    > You can inherit and extend the standard textbox.
    > Here is an example:
    > http://steveorr.net/articles/InheritAndExtend.aspx
    >
    > However, I'm not sure if you'll be able to accomplish your particular goal
    > by inheriting the textbox. If it's possible, it will take some fancy
    > Javascript.
    > Otherwise you may need to fake a textbox with a div and some fancy
    > Javascript.
    > You might be able to use a 3rd party textbox control that uses a technique
    > like this already, such as one of these:
    > http://steveorr.net/freecontrols/textboxes.aspx
    >
     
    Karl, Apr 2, 2005
    #4
  5. The javascript for the numeric textbox is compatible with IE only. I
    haven't experimented with a Firefox compatible version of it yet.
    I'm not sure what the best way to control the cursor is, and I'm not 100%
    sure it's possible.
    If you want to get into such fancy javascript, I'd suggest a good book on
    the subject such as this:
    http://www.amazon.com/exec/obidos/A...9024?creative=327641&camp=14573&link_code=as1

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




    "Karl" <-grove.com> wrote in message
    news:...
    >
    > Hi Steve,
    >
    > I don't know if you ran into this before or not. But I tried your numeric
    > textbox and it seems that the javascript does not work in FireFox. That
    > is, I can type any character I please. IE worked just fine.
    >
    > Any suggestions as to what I might have to do to rectify this? (I doubled
    > checked, Javascript is enabled.) I've copied the source of the page below
    > in case you see anything obvious.
    >
    > Oh, one other thing. :) Even in IE, the user, if they type a cursor key,
    > the cursor moves. Do you know why the browswer still responds to a
    > cursorkey stroke? It looks to me as if the Javascript should prevent that
    > as well.
    >
    > Thanks,
    > Karl
    >
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    > <HTML>
    > <HEAD>
    > <title>WebForm1</title>
    > <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    > <meta name="CODE_LANGUAGE" Content="C#">
    > <meta name="vs_defaultClientScript" content="JavaScript">
    > <meta name="vs_targetSchema"
    > content="http://schemas.microsoft.com/intellisense/ie5">
    > <LINK REL="stylesheet" TYPE="text/css" HREF="StyleSheet1.css">
    >
    > </HEAD>
    > <body MS_POSITIONING="GridLayout">
    > <form name="Form1" method="post" action="WebForm1.aspx" id="Form1">
    > <input type="hidden" name="__VIEWSTATE"
    > value="dDwtMTExMzYxMDEzOTt0PDtsPGk8MT47PjtsPHQ8O2w8aTw1Pjs+O2w8dDxwPDtwPGw8b25LZXlQcmVzczs+O2w8VmFsaWRhdGVOdW1lcmljKCk7Pj4+Ozs+Oz4+Oz4+Oz4VkqDNHdqjFodNfkCACgw0HXMbWQ=="
    > />
    > <script language=javascript>function ValidateNumeric(){var keyCode =
    > window.event.keyCode;if (keyCode > 57 || keyCode <
    > 48)window.event.returnValue = false;}</script>
    >
    >
    > <input name="TextBox1" type="text" id="TextBox1" style="Z-INDEX: 101;
    > LEFT: 344px; POSITION: absolute; TOP: 88px" />
    > <input name="TextBox2" type="text" id="TextBox2" style="Z-INDEX: 102;
    > LEFT: 344px; POSITION: absolute; TOP: 136px" />
    > <input name="NumericTextbox1" type="text" id="NumericTextbox1"
    > onKeyPress="ValidateNumeric()" style="Z-INDEX: 103; LEFT: 352px; POSITION:
    > absolute; TOP: 192px" />
    >
    > </form>
    > </body>
    > </HTML>
    >
    >
    >
    >
    > Steve C. Orr [MVP, MCSD] wrote:
    >> You can inherit and extend the standard textbox.
    >> Here is an example:
    >> http://steveorr.net/articles/InheritAndExtend.aspx
    >>
    >> However, I'm not sure if you'll be able to accomplish your particular
    >> goal by inheriting the textbox. If it's possible, it will take some
    >> fancy Javascript.
    >> Otherwise you may need to fake a textbox with a div and some fancy
    >> Javascript.
    >> You might be able to use a 3rd party textbox control that uses a
    >> technique like this already, such as one of these:
    >> http://steveorr.net/freecontrols/textboxes.aspx
    >>
     
    Steve C. Orr [MVP, MCSD], Apr 3, 2005
    #5
    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. Tomas
    Replies:
    1
    Views:
    3,140
    Teemu Keiski
    Feb 8, 2004
  2. Lau Lei Cheong

    Page.Render do not render complete page

    Lau Lei Cheong, May 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,071
    Lau Lei Cheong
    May 15, 2004
  3. Jason Dean

    Override Render method in Label Control

    Jason Dean, Dec 21, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    4,886
    bruce barker
    Dec 22, 2004
  4. sk
    Replies:
    5
    Views:
    2,257
    Shardul Kulkarni
    Mar 10, 2005
  5. Glenn Gillen
    Replies:
    0
    Views:
    278
    Glenn Gillen
    Nov 17, 2006
Loading...

Share This Page