<%@ Page Language = "VB" aspcompat=true Explicit="True"%> 
<%Dim src As String = " bet "%>

<html>
<head ></head>
<body >

<form name=loc action=testsac.aspx method=get>
<table class=s0 width=100% cellpadding=1 cellspacing=1 align=center border=1>
  <tr class=s0 align=center>
    <td>
    Search For:
    <input class=s0 size=50 name=src  value=<%=src%>>
    <input class=s0 type=submit value=Search />
    <td></td>
  </tr>
</table>
</form>

</body>
</html>

on the screen, "bet" is the search string, but I want " bet "
any ideas?

Dani AI

Generated

A quick diagnosis tied to the thread: the browser didn't "trim" your string at random — the HTML parser did. The input value in the original markup was emitted without a proper quoted attribute, so whitespace became a separator and the visible leading/trailing spaces vanished. was on the right track about markup; add proper quoting and also HTML-encode any server output so special characters and user data can't break the attribute or introduce XSS.

A practical, minimal pattern to use in classic ASP.NET is:

<input name="src" value="<%= Server.HtmlEncode(src) %>" />

This keeps any literal spaces that are actually present in the string and safely encodes characters like <, > and &. If the goal is to make leading/trailing blanks visually obvious, normal space characters are easy to miss; options are to use a textarea or to replace the specific spaces you want preserved with non-breaking-space characters (U+00A0) before rendering. Avoid inserting entity text like &nbsp; and then re-encoding the string, because that will render the entity name instead of a space.

Quick troubleshooting checklist:

  • Check the browser "View source" to see exactly what the value attribute contains.
  • Inspect the input element in the DOM (developer tools) to confirm its value property.
  • Always HTML-encode server output for attributes.
    Further reading: MDN on HTML attribute syntax and the input value attribute (Attributes) and Microsoft documentation on HTML encoding (HttpServerUtility.HtmlEncode).
<%@ Page Language = "VB" aspcompat=true Explicit="True"%> 
<%Dim src As String = " bet "%>

you knew to quote values up there , , , but, ,

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body >
<form name='loc' action='testsac.aspx' method='get'>
<table class='s0' width='100%' cellpadding='1px' cellspacing='1em' align='center' border='1px'>
<tr class='s0' align='center'>
<td>
Search For:
<input class='s0' size='50' name='src'  value='<% =src %>'>
<input class='s0' type='submit' value='Search'>
<td></td>
</tr>
</table>
</form>
</body>
</html>

Values are quoted in html,
measurements other than zero have a dimension
/> is Xhtml and may cause errors in html

for code problems where the solution doesnt jump out and bite you, plug the code into http://validator.w3.org/ and let it find the problems

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.