Render method?

K

Karl

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?
 
B

Brock Allen

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 ;)

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.
 
S

Steve C. Orr [MVP, MCSD]

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
 
K

Karl

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top