|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Render method?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? > Looking at this class's Render() method, I had expected to see code Of course it does! But it uses some other code to help ;)> that would actually draw a textbox. No such luck. > > 1) What code does draw the textbox? 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 HtmlTextWriter is a fancy wrapper on top of the Response object and its primary > Render() method.) 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 BTW, keep this up! This is how you'll learn how the innards of ASP.NET work.> code for System.Web.UI.WebControls.TextBox. -Brock DevelopMentor http://staff.develop.com/ballen 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 Show quote "Karl" <kthompson@nospam.pine-grove.com> wrote in message news:%23bZ8NcTNFHA.576@TK2MSFTNGP12.phx.gbl... > 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? 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: Show quote > 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 > 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/ASIN/0138419418/steveorrnet-20/103-4498408-3839024?creative=327641&camp=14573&link_code=as1 Show quote "Karl" <kthompson@nospam.pine-grove.com> wrote in message news:OupDEt7NFHA.1372@TK2MSFTNGP10.phx.gbl... > > 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 >> |
|||||||||||||||||||||||