Include a jscript file in asp.net using vb

J

Jer425

Hello,

I'm coding in VB and trying to include a jscript file. This will not
work because you can only use one language in asp.net. Is there a way
that I can use the jscript without having to convert it to VB? I heard
something about using a component..is this true? Options?

Thanks all!
 
K

Ken Cox [Microsoft MVP]

Hi,

You can mix and match languages via a user control.

Put your jscript in a user control such as jscriptest.ascx as shown below:

<%@ control classname="jscriptest" language="jscript" %>
<script runat="server">
function monthNum(value : Date) : int {
return value.getMonth() + 1;
}
function datetoString(value : Date) : String {
return monthNum(value)+ "/" +
value.getDate() + "/" +
value.getYear();
}
var dt = new Date();
</script>

<%
Response.Write("The month is " + monthNum(dt) +".<BR>\n");
Response.Write("Date is " + datetoString(dt) +".<BR>\n");
%>

Create a VB jscriptuse.aspx page and drop the user control onto it, as shown
below:

<%@ Page Language="VB" %>
<%@ register src="jscriptest.ascx" tagname="jscriptest" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>JScript</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:jscriptest id="Jscriptest1" runat="server" />
&nbsp;</div>
</form>
</body>
</html>

When you run the ASP.NET page, you get the content from the user control.
Perhaps this will give you the idea to expand on.

See more here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting01222002.asp

Let us know how you make out?

Ken
Microsoft MVP [ASP.NET]
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top