replace spaces with from a recordset - asp-classic

How can I change "spaces" on records being returned by a recordset?
For example, I have this code that will return a value of "John Doe":
<td width="30%"><%=rsTmp("Name")%></font></td>
What I would like to do is to change the space between the words into:
so that when my page got congested the name "John Doe" will still be in a straight line, and will not be separated?

In Classic ASP you will need to code the following:
<%= Replace(rsTmp("Name")," "," ") %>
Which is the same as
<%
Response.Write ( Replace(rsTmp("Name")," "," ") )
%>

Actually, I would suggest using replace(rsTmp("Name"), " ", " ")
In HTML5 the ASCII code are replaced with  . You might as well do this from this day and onwards ;)

I resolved it!
I used replace function like this.
<% Replace(rsTmp("Name")," "," ")%>

Related

ASP, Forms and passing variables between frames

I am pretty new to ASP, I know VBScript reasonably well though. What I am trying to do is create a website with 2 frames. In the top frame, it asks for a year (from a selection box) and a week number (from a selection box). It should then display the dates relating to the selection and a button to process the request. When the button is clicked the bottom form then processes a SQL query based on the selection in the top frame and displays the info.
Now, my problem is when it comes to understanding ASP. With ASP, all the code is processed then the output is sent to the browser. How do you update variables or even pass them to other frames when the code has already processed?
I just need some pointers on the way forward to accomplishing the above.
Thanks
First off, don't use frames: they're annoying, ugly, and outmoded.
You can do something like this in asp, but it's going to require a round trip (or two) to the server.
The basic outline of the page (let's call it thispage.asp) would be something like
<html><head>[head stuff]
<%
dim yr, wk, i
yr = request.form("Year")
wk = request.form("Week")
'- if you use form method='get', then use request.querystring("Year")
if not isnumeric(yr) then
yr = Year(date) 'or whatever else you want to use as a default
else
yr = CInt(yr)
end if
'similar validation for wk
%>
</head>
<body>
<form method="post" action="thispage.asp">
<select name="Year" size="1">
<%
for i = Year(Date) - 2 to Year(Date) + 2
response.write "<option value='" & i & "'"
if i = yr then response.write " selected"
response.write ">" & i & "</option>"
next
%>
</select> [similar code for week or date or whatever]
<input type="submit">
</form>
<%
If yr <> "" and wk <> "" Then
'- look up stuff in database and output the desired data
'- (this part will be much longer than this)
Else
Response.Write "<p>Please make your selections above.</p>"
End If
%>
</body></html>
If you need to output form fields that are dependent on the user's initial year & week selections, then you're going to need more than one trip to the server, but it's still the same idea: set up the variables you're going to need, see if they have values, write out the form, and then if all the necessary variables have all the necessary values, then you can do your output stuff.

How to handle ampersands in URL parameters?

I am having the following issue:
I am using an application that allows users to concatenate text to build a URL that passes parameters to an ASP page via GET method, i.e. something like:
http://myhostname/process.asp?param1=value1&param2=value2
Problem is value1 and value2 can contain the ampersand symbol, which is not interpreted as a text character.
The most popular solution to this issue is to encode the URL, which is not an option for me because I cannot modify the program that builds the URL. I can modify the process.asp page, but not the program that concatenates the text fields and builds the URL.
Things I've tried to search for are:
How to encode a URL using javascript directly in the browser
How to change IIS default behaviour when reading an &
Alternative ways to pass parameters, i.e. something like passing them as a single string of characters separated with pipes
Hope you can give me some guidance.
You can read the entire query string and parse it yourself, like this:
q = Request.QueryString
a = Split(q, "=")
i = 1
For Each s In a
If i mod 2 = 0 Then
If InStr(s, "&") <> InStrRev(s, "&") Then
Response.Write "Value: " & Left(s, InStrRev(s, "&") - 1) & "<br/>"
hidingParam = Right(s, Len(s) - InStrRev(s, "&"))
Response.Write "PAramName: " & hidingParam & "<br/>"
i = i + 1
Else
Response.Write "Value: " & s & "<br/>"
End If
Else
Response.Write "PAramName: " & s & "<br/>"
End If
i = i + 1
Next
Result:
URL: ...?Q=abc&def&P=123 produces
PAramName: Q Value: abc&def PAramName: P Value: 123
Note that this is less than robust. I am only illustrating my idea. I didn't test with no &.
It also doens't handle multiple "=" characters (if that's a possiblity as well).
If there are 2 (or more) ampersands in-between the equals, then only the last one is a parameter separator. So, using your URL above, and assuming that value1 = "abc&def", and value2 = "123", then the URL will look like:
http://myhostname/process.asp?param1=abc&def&param2=123
Notice there's 2 ampersands in-between the 2 equals. The last one will be your parameter separator, the rest are part of the value. And any ampersands after the last equals are also part of the value.
You'll have to dissect the incoming URL and apply the appropriate logic.

Can't set value of hidden input to comma seperated list in ASP VB.net

Hi I've run into a really annoying problem, I'm trying to set the value of a hidden input to a comma seperated list taken from a database but in pure CSV format it won't set the value.
The input tag and ul tag looks like this (I am aware of asp:hiddenfield and it's value property but I'm not using it as I still have this issue):
<ul id="keywords" runat="server">
</ul>
<input type="hidden" id="keywordsBox" runat="server" />
The code I'm using to populate it is:
'connection strings and all that stuff is set up and using a SqlDataReader to sort through results
while result.Read()
keywordsBox.Attribute.Add("value", result.Item("keywords"))
keywords.innerHTML = "<li>" & Replace(result.Item("keywords"),",","</li><li>") & "</li>"
End while
This will populate the li tags but will not populate the value for the input, I've tried using the replace function on the list for the value but it only works if I remove the commas or put other characters infront of them. I've also tried replacing it with the HTML code for a comma but just prints the HTML code out.
Has anybody else ran into this at all? How'd you fix it?
Try the below code, this will solve your problem:
dim hValue as string =""
while result.Read()
hValue += result.Item("keywords")
keywords.innerHTML = "<li>" & Replace(result.Item("keywords"),",","</li><li>") & "</li>"
End while
keywordsBox.Attribute.Add("value", hValue )

how to have title in double quotes in html or asp tag

For a title tag, I have given as title="I name accept " and it shows as I name accept.
But I want to give title as I "name" accept. How to put double quotes for a title tag in double quotes.
thanking you,
michaeld
Use " instead.
Title="I "name" accept"
Try this:
title="I "name" accept"
You could do it like this too:
title='I "name" accept'
But I would go with the first one :)
Use the following:
Title = 'I "name" accept'
You could use the HTML code of the ASCII character. Here's the table of HTML Codes - Characters and symbols
Double quotes should be: "
Try using ASCII characters, the character for " is "
HTML ASCII Reference

Best Technique for Multiple Eval Fields in Gridview ItemTemplate?

What is the best way to use multiple EVAL fields in a GridView ItemTemplate?
Looking to have some control over formatting for appearance as well as setting up hyperlinks/javascript etc.
Even clearer, IMO, is:
<%# String.Format("{0} - {1}", Eval("Name1"), Eval("Name2")) %>
I had previously used this (bad, I know):
<%# Eval("Name1", "{0} - ")%> <%#Eval("Name2")%>
Result = 'John - Smith'
But just discovered that I can also put TWO (or more) Evals in the same data-bound group:
<%#Eval("Name1") & " - " & Eval("Name2")%>
Result = 'John - Smith'
Or
<%# "First Name - " & Eval("Name1") & ", Last Name - " & Eval("Name2")%>
Result = 'First Name - John, Last Name - Smith'
Eval and Bind both suck.
Why get the property through reflection? You can access it directly like this:
((MyObject)Container.DataItem).MyProperty
It's not like the object is unknown to you at runtime. That's my two cents, anyhow.
I have a easiest way to do this same thing...
<asp:Label ID="lblName" runat="server" Text='<%#Eval("FirstName").ToString() +", "+ Eval("LastName").ToString() %>'></asp:Label>
.
<%#Eval("FirstName").ToString() +", "+ Eval("LastName").ToString() %>
Here both objects are converted into string the concatenate them.

Resources