Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextBox DTC Alignment

Status
Not open for further replies.

TimOSullivan

Programmer
Mar 9, 2001
13
0
0
IE
Hi,
I'm tearing my hair out with this one.

Is there any way to change the alignment of the text in a textbox dtc (V.Interdev 6.0)?
Also, font type, font size etc.?

I've no problems with normal HTML textboxes (INPUT).
I'd appreciate any help with this.

Thanks,
Tim
 
Tim,

I had success over a year ago using two different techniques. I don't have any of the code available and I am going off of my memory here.

One technique was to modify the _ScriptLibrary files to create new behavior that you develop. There is a sort of easy 'hack' to accomplish this.

Another was to modify the attributes of the HTML element using client side script. To avoid re-writing the client code for each effort you can create your own server code that will generate the client side script code in a re-usable fashion.

Both techniques require attention to browser compatibility issues if that is desired.

Hope this helps
-pete
 
I'm having a similar set of difficulties with DTC text boxes and option groups. I want to change the font face, size, and style but have not yet been successful. The reason I would like to use DTCs is to take advantage of their visible property. Does anyone know how to control the visibility of an HTML input tag?
 
trimble,

> Does anyone know how to control the visibility of an HTML input tag?

Well if you 'View Source' on the resultant page after unchecking the 'Visible' property of a DTC Textbox you will see that the HTML.INPUT element is not written to the page. So that's how the DTC's do it.

-pete
 
Thanks for the advice Pete.
I also got the solution from a MS News group and is as follows:

For example, if you have a server-side textbox called Textbox1, it will make a client side textbox called "Textbox1" in the form created called "thisForm". So you could do this in the 'onload event':

<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function window_onload() {
document.thisForm.Textbox1.style.width = &quot;150px&quot;;
document.thisForm.Textbox1.style.fontFamily=&quot;serif&quot;;
document.thisForm.Textbox1.style.color=&quot;blue&quot;;
document.thisForm.Textbox1.style.backgroundColor=&quot;#fafad2&quot;
document.thisForm.Textbox1.style.textalign=&quot;right&quot;

}
//-->
</SCRIPT>

This works a charm on IE. Not sure about Netscape.
Pete, what sort of server code do I need to produce this?
Any example?

Thanks,
Tim
 
Tim,

> Pete, what sort of server code do I need to produce this?

Well you don't 'need' any. Is your question regarding my first post comments?

Another was to modify the attributes of the HTML element using client side script. To avoid re-writing the client code for each effort you can create your own server code that will generate the client side script code in a re-usable fashion.


I will try to post the entire page here, ok it shows up in preview so I will post it. Now this is just an example that I threw together in a few minutes, the key to success in code reuse is design. There is no design in this sample code, just a quick example of how you can use server code to produce client HTML and/or Script.

Hope this helps
-pete


<%@ Language=JavaScript %>
<SCRIPT id=DebugDirectives runat=server language=javascript>
// Set these to true to enable debugging or tracing
@set @debug=false
@set @trace=false
</SCRIPT>
<% // VI 6.0 Scripting Object Model Enabled %>
<!--#include file=&quot;../../_ScriptLibrary/pm.asp&quot;-->
<% if (StartPageProcessing()) Response.End() %>
<FORM name=thisForm METHOD=post>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<SCRIPT LANGUAGE=javascript RUNAT=Server>
function ClientElement( sElementName){
this.name = sElementName;
this._settings = new Array();

// prototypes
this.put = ce_putSetting;
this.toClientScript = ce_toClientScript;

function ce_putSetting(sSetting, sValue){
this._settings[this._settings.length] =
new String(sSetting + &quot;=\&quot;&quot; + sValue + &quot;\&quot;&quot;);
}

function ce_toClientScript( sFormName){
var sret = new String();
for( j=0; j<this._settings.length; j++){
sret += &quot;document.&quot; + sFormName + &quot;.&quot; + this.name +
&quot;.&quot; + this._settings[j] + &quot;;\r\n&quot;;
}
return sret;
}
}
</SCRIPT>

<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--

function window_onload() {
if ( 'function' == typeof(dtc_onload))
dtc_onload();
}

//-->
</SCRIPT>
</HEAD>
<BODY LANGUAGE=javascript onload=&quot;return window_onload()&quot;>

<P>Textbox1</P>
<!--METADATA TYPE=&quot;DesignerControl&quot; startspan -->

***** removed for brevity *****

<!--METADATA TYPE=&quot;DesignerControl&quot; endspan-->
<%
var oTxt1 = new ClientElement(&quot;Textbox1&quot;);
oTxt1.put(&quot;style.width&quot;,&quot;150px&quot;);
oTxt1.put(&quot;style.fontFamily&quot;, &quot;serif&quot;);
oTxt1.put(&quot;style.color&quot;, &quot;blue&quot;);
%>
</BODY>
<SCRIPT LANGUAGE=javascript>
<!--
function dtc_onload(){
<%=oTxt1.toClientScript(&quot;thisForm&quot;)%>
}
//-->
</SCRIPT>

<% // VI 6.0 Scripting Object Model Enabled %>
<% EndPageProcessing() %>
</FORM>
</HTML>
 
Look at the function _TXT_display(bReturnText) in _ScriptLibrary/TEXTBOX.ASP and all will become clear!

The textbox is rendered in a number of formats depending on the Browser and the Properties. For example, a 'disabled' textbox can be rendered as an INPUT in IE, but must be mimicked using a TABLE for Netscape.

I have adjusted this function to include a stylesheet class name to the output HTML. (see below).

If you need to add an attribute to the textbox (alignment) then you may add attributes to the _TXT__Prototype() function. But please note the following:
1. You may set these attributes on an ASP page in the thisPage_onenter
2. VI will not 'pop-up' properties/methods that you create. So document these carefully!
3. So the textbox 'remembers' the settings on each round trip, you may want to add any new properties to the _TXT__PreserveState / _TXT__RestoreState methods. Alternatively, ensure you set the values in the thisPage_onenter function.

Good Luck!

To add a stylesheet name, adjust the display method:

if (this._nStyle == TXT_PASSWORD)
strHTML = '<' + 'INPUT type=&quot;password&quot; id=&quot;'
else
strHTML = '<' + 'INPUT type=&quot;text&quot; id=&quot;'
strHTML += this.id + '&quot; name=&quot;' + this.name + '&quot;';
...etc...
strHTML += ' class=&quot;clsTextBox&quot;'; //to allow link to style sheet
...etc...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top