how to use ASP code inside ASP.NET ?
is it possible to run ASP script code inside ASP.NET page ?
If so, please give an example.
thanks
--
ASP code might look like this. So how do we such such script inside ASP.NET ?
Function changeColor(value, random)
Dim colorArray
colorArray = Split(value, ",")
divBlockColor = colorArray(random Mod (UBound(colorArray) + 1))
End Function
I'm affraid it isn't possible, as ASP Code runs in a different application environment as asp.Net. That's also why for example session("xyz") is not shared between Classic ASP and ASP.Net web pages in the same website.
What you could do is leave the asp code in a .asp page, and use forms with POST to go back and forth to the asp code. This way you will not have to rewrite the entire .asp environment, and you can migrate to .Net one bit at a time.
This way you can leave all your existing code, and use simple javascript to automatically submit the forms, posting the values back to .Net
Related
Do any out there know how to Execute Powershell code on ASP MVC 5? Or maybe some link to a guide.
I know this guide but the writter use ASP Web Form, I'm new using MVC (actually ASP in general) so is kind of hard to transalte the stuff.
Guide: http://jeffmurr.com/blog/?p=142
This article tells pretty much everything.
If you are unfamiliar with ASP.NET MVC, I'd advise you to go through the basics first. Then everything should become way clearer.
Instead of using ExecuteCode_Click to execute your script, you need to create a controller and some action in it and put the code in there.
Action should accept a string value with your script, do the processing, and return the result a ViewResult with script result as a property on your model.
The view could then render the result as you see fit (eg. inside an HTML textbox).
I have an asp page that uses includes to include certain pages depending on the query string.
I have built an addition to this page in asp.net and want to include my new page in the asp page, but i get this error.
Active Server Pages error 'ASP 0140'
Page Command Out Of Order
/d//Default.aspx, line 1
The # command must be the first command within the Active Server Page.
You can't include ASP.NET pages inside of an ASP page. You do, however, have a couple of options.
The easiest would be to include the ASP.NET page as an IFrame on your ASP page. You can use ASP to dynamically set the URL of the IFrame on the server side.
The other option would be to write a wrapper .NET DLL that would render your page via a method. You could then register that DLL in COM+ so that it could be called by VBScript in your ASP pages. Obviously this is more complicated.
If the first option works, go for it. Otherwise you might have to figure out how to implement the second.
I'm pretty sure the include functionality in ASP is strictly for including other ASP files which contain code to be parsed by the ASP engine. It wouldn't know what to do with ASP .NET code.
You can't include an ASP.NET page in an ASP page. You can't mix them in the same response.
Use Response.Redirect to make a redirect to the ASP.NET page instead.
Note that you are actually not selecting what page to include in your ASP page, you are always including all of the pages, as the include is done before any ASP code starts, and then the conditional statements only decide which of the pages to run.
I agree with Justin Niessner's options, but there is also another easy way to include the contents of the ASP.net page into your Classic ASP page, which might suit your needs.
If you want to include the resulting Html of the ASP.net page, you can take the following approach:
Dim Url
Url = "http://pathtoyourasp.net/script/somescript.aspx?param=value"
' Create XML object, make server side request
Dim objXML: set objXML = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXML.Open "GET", Url, True
objXML.Send
' Retry a few times just in case: it's classic ASP.
Dim try_times: try_times = 0
While objXML.ReadyState <> 4 and try_times < 5
objXML.waitForResponse 2
try_times = try_times + 1
Wend
If objXML.ReadyState = 4 then
' Success, write the response
Response.Write objXML.ResponseText
Else
' Failed, show error
Response.Write "The page failed to load."
End If
Set objXML = Nothing
i am new to ASP.NET development, and i am a little bit curious on the asp.net code behind mechanism.
i know why we use it
but what i would like to know is:
the relation between aspx page and the code behind
who does the linking between these two separate files ?
how does it work?
how an element created in aspx page can be accessed directly from code behind ?
I mean what happens BEHIND THE SCENES ?
thanks
I have an ASPX based component which I'd need to inlude into a plain ASP based
script. Scenario is, that I'm working within an LMS system (Angel to be exact)
and I wan't to create a new nugget within that framework. An Angel nugget is
pretty much what a portlet is in the Java world.
Now, the nugget spec. states that my starting point has to be a file called
default.asp. What I'd like to do is:
read relevant data from ASP session
pass data to ASPX component
have ASPX do it's job and display the results
My problem is that I fail to run / display my ASPX component without
using an iframe, which I want to avoid since that crushes the layout /
design of my nugget.
Is there a way to get this done properly or do I have to rewrite my
component in ASP to get this going?
Note: the component performs
web service queries and such and I'd like to avoid rewriting that.
Why don't you grab the .aspx content from the .asp page using the MSXML object?
url = "http://www.yoururl.com/YourPage.aspx?relevantData=YourRelevantData"
Set xml = Server.CreateObject("Msxml2.SERVERXMLHTTP")
xml.Open "GET",url,False
xml.send
html = xml.ResponseText
Set xml = Nothing
Response.Write(html)
I'm trying to implement this specific example using asp.net page instead of asp page.
If you look at the example you can see that there are 2 parts for the page:
Mail asp page. This page have JS code that calls other asp file for AJAX use.
the other asp page which holds the JS code.
The responseText of the call is the client side code, so, when I write something like this:
<html><head><title>test</title><script language="javascript" runat="server"
type="text/javascript">function test(){Response.Write("This is a Test!");
</script><body onload="test()"></body></html>
the page ignores my server side code and returns this:
<html><head><title>test</title><body onload="test()"></body></html>
what should I need to do to make him process my JS code and return its output?
Thanks in advance,
Oz Radiano.
asp.net does not process javascript server side, so setting the script tag runat=server with language="javascript" will be mostly ignored.
I think if you change it to "JScript" it will work, however, this has nothing to do with ajax.
"runat = server" says, preprocess this on the server and don't send it to the client.
If the language is a processable one it will be evaluated as well.
Try implementing the example after watching some videos from http://www.asp.net/learn/ajax-videos/ and http://www.asp.net/learn/ajax/
Its very easy to implement AJAX in asp.net then ASP. I can clearly give you the correct source code. :) But you seem to try out new things. Let us know how it goes!
Thanks for your responses, they made me understand that I'm not sure what my problem is.
After failing in implementing this exact example, I've googleed "how to run asp code using ajax"
this result returned and made it very clear.
Thanks again.