I am supporting an old Classic ASP application and I've read that the code we write within <% %> is VBScript and <% Response.Write "VBScript" %> is working fine , but when I write in the following format, Response.Write is not working
<SCRIPT LANGUAGE="VBScript">
Response.Write "VBScript"
</SCRIPT>
also Response.Write is not getting executed in an button click event
<SCRIPT LANGUAGE="VBScript" >
function B3_OnClick()
FORM1.T3.style.backgroundColor = "white"
FORM1.T4.style.backgroundColor = "white"
FORM1.T3.readOnly ="false"
FORM1.T4.readOnly ="false"
FORM1.style.backgroundColor = "white"
Response.Write("Hello World")
End function
</SCRIPT>
Can Anyone explain me why? Is there any substitute for Response.Write in that case..? Thanks in advance
This is because you are missing the runat="Server" attribute in the <script> tag.
<SCRIPT LANGUAGE="VBScript" runat="Server">
Response.Write "VBScript"
</SCRIPT>
Remember VBScript accessed through Classic ASP happens before the response is sent to the client. For an action such as clicking a button on the client to affect the server-side code it has to make a round-trip to the server. If you want to have server-side code affect client-side code you can inject code before returning a server response to the client.
<SCRIPT LANGUAGE="VBScript" >
function B3_OnClick()
FORM1.T3.style.backgroundColor = "white"
FORM1.T4.style.backgroundColor = "white"
FORM1.T3.readOnly ="false"
FORM1.T4.readOnly ="false"
FORM1.style.backgroundColor = "white"
MsgBox "<% Response.Write("Hello World") %>"
End function
</SCRIPT>
Useful Links
Answer to Access client variable within server-tags in vbscript
Answer to what's the difference between <% %> and in classic asp?
Related
There is a code for filtering fields from a query (fname, lname and location) into a DataGridView:
Dim DV As New DataView(dbdataset1)
DV.RowFilter = String.Format("fname like '%" & Me.tbSearch.Text.Trim & "%'")
DataGridView.DataSource = dbdataset1
The filter can find lname, location but not fname:
here is the screen shot of the populated fields
As for the DataGridView element I can tell you're on ASP.NET 2.0 or below. Anyway, I got it working on ASP.NET 4.7 like this:
ASPX file:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>
<asp:TextBox ID="tbSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" />
</form>
</body>
</html>
Code behind (VB.Net):
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Private Sub form1_Load(sender As Object, e As EventArgs) Handles form1.Load
End Sub
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
Dim dbdataset1 As New DataTable
Dim dr As DataRow
dbdataset1.Columns.Add("fname")
For i As Integer = 1 To 3
dr = dbdataset1.NewRow()
dr("fname") = "picture" + i.ToString()
dbdataset1.Rows.Add(dr)
Next
For i As Integer = 1 To 3
dr = dbdataset1.NewRow()
dr("fname") = "document" + i.ToString()
dbdataset1.Rows.Add(dr)
Next
Dim DV As New DataView(dbdataset1)
DV.RowFilter = String.Format("fname like '%" & Me.tbSearch.Text.Trim & "%'")
Me.GridView1.DataSource = DV
Me.GridView1.DataBind()
End Sub
End Class
Just replace my GridView1 with your DataGrdiView.
UPDATE:
So the filter was fixed by the user deleting and adding the Texbox control again into the form.
I am trying to Ajax Call on Search Container Pagination. As there are more than one portlet on same page I don't want to each portlet to forcefully call render every time when I do Pagination.
There could be 2 possible solutions but I am facing some problem. Please help me to solve it.
1) Can you please tell me how to edit Liferay Search Container Pagination URL by changing its Portlet Life-cycle from 0 to 2 ? How to create hook ?
2) There is a tag called <liferay-ui:page-iterator/> in which there is a attribute called jsCall. It is used for pagination without page reloading. I am unable to find out how to use it ?
If it can be solved using 2nd option then it would be much helpful.
Thank You.
kanakhara,
Each time I faced that problem I had to implement manually a pagination because search-container is really embedded to be modified by a developer.
Maybe could be a solution to this problem but it's not sure that it exists.
You'll spend less time creating your own pagination for this purpose.
I hope it can help you.
Best wishes
Yes, I know how to use it.
I'll give you an example to do it:
<portlet:renderURL var="manageRelationsURL"
windowState="<%=LiferayWindowState.NORMAL.toString()%>">
<portlet:param name="action" value="manageRelations" />
</portlet:renderURL>
<%PortletURL iteratorURL = renderResponse.createRenderURL();
iteratorURL.setParameter("action", "manageRelations");
%>
<%
PortalPreferences portalPrefs = PortletPreferencesFactoryUtil.getPortalPreferences(request);
String orderByCol = ParamUtil.getString(request, "orderByCol");
String orderByType = ParamUtil.getString(request, "orderByType");
if (Validator.isNotNull(orderByCol) && Validator.isNotNull(orderByType)) {
portalPrefs.setValue("NAME_SPACE", "order-by-col", orderByCol);
portalPrefs.setValue("NAME_SPACE", "order-by-type", orderByType);
} else {
orderByCol = portalPrefs.getValue("NAME_SPACE", "order-by-col", "domainLabel");
orderByType = portalPrefs.getValue("NAME_SPACE", "order-by-type", "asc");
}
%>
<div style="">
<aui:form>
<liferay-ui:search-container delta="20" iteratorURL="<%=iteratorURL%>" emptyResultsMessage="There were not any match." orderByCol="<%= orderByCol %>" orderByType="<%= orderByType %>">
<liferay-ui:search-form
page="/WEB-INF/jsp/localAdministration/relations/search.jsp"
searchContainer="<%= searchContainer %>"
servletContext="<%= this.getServletConfig().getServletContext() %>"
showAddButton="true" />
<liferay-ui:search-container-results>
<%
List<RelationInstance> relationList = UtilsAdministration.getRelationListCache(themeDisplay.getUserId(),0, UtilsAdministration.getRelationListCacheSize(themeDisplay.getUserId()));
Collections.sort(relationList,RelationsComparator.getRelationsOrderByComparator(orderByCol, orderByType));
results = ListUtil.subList(relationList, searchContainer.getStart(),
searchContainer.getEnd());
if(relationList.size()<searchContainer.getEnd()){
results = ListUtil.subList(relationList, searchContainer.getStart(),
relationList.size());
total = relationList.size();
}else{
results = ListUtil.subList(relationList, searchContainer.getStart(),
searchContainer.getEnd());
total = relationList.size();
}
pageContext.setAttribute("results", results);
pageContext.setAttribute("total", total);
%>
</liferay-ui:search-container-results>
<liferay-ui:search-container-row className="RelationInstance" modelVar="aRelationInstance">
<liferay-ui:search-container-column-text name="First" value="<%=aRelationInstance.getFirstLabel()%>" orderable="<%= true %>" orderableProperty="domainLabel"/>
<liferay-ui:search-container-column-text name="Second" value="<%=aRelationInstance.getSecondLabel()%>" orderable="<%= true %>" orderableProperty="relationLabel"/>
<liferay-ui:search-container-column-text name="Third" value="<%=aRelationInstance.getRangeLabel()%>" orderable="<%= true %>" orderableProperty="rangeLabel"/>
<liferay-ui:search-container-column-jsp align="right" name="Acciones" path="/WEB-INF/jsp/localAdministration/relations/actionRelationButton.jsp"/>
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
</aui:form>
</div>
In this case I retrieve the list to iterate from EhCache instead of DB.
IteratorURL must contains the same URL that the page you're invoking.
I hope it could be useful for you.
I am getting the following error when i load an ASP page that calls a stored procedure from SQL 2000 with a parameter used at the point of loading the ASP page.
have i made a schoolboy error? and how do i fix this?
error
Microsoft VBScript compilation error '800a0408'
Invalid character
/simon/stock_test.asp, line 6
declare #serial varchar(255)
--------^
and the page is stock_test.asp?ID=980028001365274
<!--#include file="includes/functions_test.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
declare #serial varchar(255)
set #serial = Request.QueryString("ID")
Call OpenDB()
Call OpenRecordSet(stock, "Exec sp_report_simon_test #serial")
%>
<html lang="EN">
<head>
<title>Stock</title>
</head>
<body>
<table id="test">
<tr>
<td><b>Make</b></td>
<td><b>Model</b></td>
<td><b>Serial</b></td>
</tr>
<%DO WHILE NOT stock.EOF%>
<tr>
<td><%=stock.Fields("Make").value %></td>
<td><%=stock.Fields("Model").value %></td>
<td><%=stock.Fields("serial_number").value %></td>
</tr>
<%
stock.MoveNext
LOOP
%>
</table>
<%
Call CloseRecordSet(stock)
Call CloseDB()
%>
</body>
</html>
functions file
<%
response.Charset="utf-8"
Session.lcid = 2057
Response.Buffer = False
Server.ScriptTimeout=200
Dim dbConn
Function OpenDB()
Set dbConn = Server.CreateObject("ADODB.Connection")
dbConn.Open "Driver={SQL Server}; Server=server_name; Database=db_name; UID=username; PWD=password; Option=4"
End Function
Function CloseDB()
If ucase(TypeName(dbConn)) = "OBJECT" Then
dbConn.Close
Set dbConn = Nothing
End If
End Function
Function OpenRecordSet(RecSet, SqlQuery)
Set RecSet = Server.CreateObject("ADODB.Recordset")
Set RecSet = dbConn.Execute(SqlQuery)
End Function
Function CloseRecordSet(RecSet)
RecSet.Close
Set RecSet = Nothing
End Function
Function ProcessSql(Sql, Page)
Call OpenDB()
dbConn.Execute(Sql)
Call CloseDB()
If Len(Page) > 0 Then
Response.Redirect(Page)
End If
End Function
Function Encode(DirtyText)
Dim CleanText
Cleantext = Server.HtmlEncode(DirtyText)
CleanText = Replace(CleanText, "'", "''")
CleanText = Replace(CleanText, vbCrLf, "<br>")
Encode = CleanText
End Function
Function mySqlDate(rawDate)
Dim dateString
dateString = DatePart("yyyy", cdate(rawDate))
dateString = dateString & "-" & DatePart("m", cdate(rawDate))
dateString = dateString & "-" & DatePart("d", cdate(rawDate))
mySqlDate = dateString
End Function
Function GetMonthName(monthId)
Dim monthNames
monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
GetMonthName = monthNames(monthId -1)
End Function
Function CheckQueryString(Qstring, QName, Page)
If Not Len(QString) = 0 AND Len(QString) < 6 AND IsNumeric(QString) Then
QName = QString
Else
Response.redirect(Page)
End If
End Function
%>
It's commendable that you try to use SQL parameters, but they don't work this way in ASP. It should be self-evident that you cannot simply drop SQL into your ASP code.
Use a Command object instead.
Dim stock, serialVal
OpenDB()
serialVal = Request.QueryString("serial")
If serialVal = "" Then serialVal = vbNull
With Server.CreateObject("ADODB.Command")
Set .ActiveConnection = dbConn
.CommandText = "sp_report_simon_test"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("#serial", adVarChar, adParamInput, 30, serialVal)
Set stock = .Execute
End With
Docs:
MSDN: Command Object (ADO)
MSDN: Parameters Collection (ADO)
MSDN: CreateParameter Method (ADO)
To be able to use constants like adCmdStoredProc directly in the VBScript code they must be made available by referencing their type library at the top of your ASP page.
For Windows 7/Windows Server 2008 and up, use version 6.1:
<!--metadata
type="TypeLib"
name="Microsoft ActiveX Data Objects 6.1 Library"
uuid="B691E011-1797-432E-907A-4D8C69339129"
version="6.1"-->
For earlier versions (Windows XP/Windows Server 2003), use version 2.8:
<!--metadata
type="TypeLib"
name="Microsoft ActiveX Data Objects 2.8 Library"
uuid="2A75196C-D9EB-4129-B803-931327F72D5C"
version="2.8"-->
I have a question.
I am learning classic ASP today for my next project. I am currently a .NET developer and using ASP.NET on that project is not a requirement of my client.
I have below a login page script.
Default.asp
<form method="post" action="ASP/aspLogin.asp">
form code here...
<input type="submit" class="Button Is_Default" value="Login"></input>
</form>
Now, what I have in my test ASP/aspLogin.asp page is as follows:
ASP/aspLogin.asp
<%# Language="VBScript" %>
<%
Dim strUsername
Dim strPassword
strUsername = Request.Form("txtUsername")
strPassword = Request.Form("txtPassword")
If strUsername <> "" And strPassword <> "" Then
Response.Redirect("Index.asp")
End If
%>
When I ran the scripts above, the browser just redirected me to ASP/aspLogin.asp. I would want to redirect the user to his respective home page.
My objective is that I want my ASP/aspLogin.asp file do the processing of my form instead of placing the process above the Default.asp page. May I know if I missed something out here or there are some more things to consider to create the code I need. Resources would be also appreciated.
If you have users logging in and out then I'd use session variables (which I'm sure you've encountered in .net), so something along the lines of.
If strUsername <> "" And strPassword <> "" Then
Session("Username") = strUsername
Response.Redirect("Index.asp")
End If
You would then be able to add logic to index.asp and any other page to display data depending on the value of Session("Username").
This code demonstrates the concept. Obviously you would need to ensure that usernames aren't duplicated. In practice I'd recommend a database query to retrieve the primary key value of the users record which corresponds to both username and password
Edit.
So you're basically trying to emulate .net with Classic ASP. Two things to remember. Classic doesn't have code behinds, and a .net webform can only be posted to itself, (which gets really frustrating for someone moving from Classic to .net)
Probably you're best option is to have your form page post to itself and put your processing code at the top of Default.asp, with logic which only triggers it if there's a form submission, ie
<%# Language="VBScript" %>
<%
Dim strUsername
Dim strPassword
strUsername = Request.Form("txtUsername")
strPassword = Request.Form("txtPassword")
If strUsername <> "" And strPassword <> "" Then
'Your processing code
Response.Redirect("Index.asp")
End If
%>
<html>
<body>
<form method="post">
form code here...
<input type="submit" class="Button Is_Default" value="Login"></input>
</form>
</body></html>
An extension of this method would be to use asplogin.asp as an include. (You would need to remove the <%# Language="VBScript" %> from the top of asplogin.asp, as it would become the middle of a page and you would already have your declaration in default.asp). Default.asp would then look like this.
<%# Language="VBScript" %>
<!--#include file="ASP/aspLogin.asp"-->
<html>
<body>
<form method="post">
form code here...
<input type="submit" class="Button Is_Default" value="Login"></input>
</form>
</body></html>
This is about as close as you can get to having a codebehind in Classic
i have a controller with a model which i do addAttribute("show", "yes");
how do I retrieve this value inside javascript?...assuming I have jstl
Inserting it in a javasript would be the same as showing it in the html code of the jsp.
Try to do this:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
...
Show value is <c:out value="${show}"/>
if you can see the value in the JSP then JSTL is working. In any other case there may be another problem. For example that your configuration ignores EL. You can add this at the top of your JSP:
<%# page isELIgnored="false" %>
When you see the value in the HTML code then the JSTL is working in that case you can use it in Javascript. As your setting the value for tha variable "show" to yes it cannot be used as a boolean value (because it should be true or false). In this case you should use it as a string adding quotations
<script type="text/javascript">
var showVar = '<c:out value="${show}"/>';
alert("The variable show is "+showVar);
</script>
You can use Firebug to check that your javascript is working and you don't have any error on it.