Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing ASP.NET with ASP

This might be a crazy question (I'm somewhat new to ASP.NET). But is it possible to mix ASP.NET code with classic ASP e.g. embedded a form created in ASP.NET in a classic ASP page?

like image 362
SuperFurryToad Avatar asked Jul 05 '11 12:07

SuperFurryToad


People also ask

Is it possible to combine asp net webforms and ASP MVC and develop a single Web application?

Luckily, the answer is yes. Combining ASP.NET Webforms and ASP.NET MVC in one application is possible—in fact, it is quite easy. The reason for this is that the ASP.NET MVC framework has been built on top of ASP.NET.

Is ASP.NET and ASP.NET MVC same?

The primary difference between ASP.NET MVC and ASP.NET Core is their cross-platform approach. ASP.NET Core can be used on Windows, Mac, or Linux, whereas ASP.NET MVC can only be used for applications on Windows.

Is ASP.NET still relevant 2020?

After a strong legacy of over two decades now, the net development services still remain relevant. As per a report by w3techs, ASP.NET is still used by 7.9% of all the websites whose server-side programming languages are known.

Can MVC and ASP.NET coexist?

Yes. MVC is just a different implementation of the IHttpHandler interface so both classic ASP.NET and ASP.NET MVC pages can coexist in the same app.


2 Answers

No you can not*

asp pages are basic simple pages that are actually running stand alone scripts on server side, and server returns the result. Every page is alone.

asp.net pages are a complete program that are connected together because they running under one pool, compile them all together in a single directory with many sub-directories, have special directories and other options. The pool that run the pages handle some common data, and session states, and many other thinks.

So you can have a full asp.net setup for your site, that first make it run, and then you can probably use some asp page to do some extra work until you transfer them all to asp.net

So the two are not have any relative together, so in simple answer you can not embedd anything from one to the other.

Ways of sharing data between asp and asp.net

  • You only can use iframe tricks to load one page into the other, but they still different and I do not like the idea.
  • You use some ajax tricks to get and send data. No so cool idea also.
  • You can use also a common database to share data.
  • You can use same cookies to share data.
  • You can not have the same session data (except with custom library for session like groat.com).
  • You can share files.

* Except if you code is so simple like

<% IF Len(SomeString) < 3 then %>
Ok something here
<% end if %>

In this case the code is simple running on both pages, but they are not embedded asp in asp.net, is complete render one page over one of the two.

The #include Directive is valid on both, but on asp.net is not going to compile the included file as on asp.

They have some common way of typing code but they are totally different, and you need start thinning different when you go to move from asp to asp.net

like image 197
Aristos Avatar answered Nov 14 '22 08:11

Aristos


Generally, the answer to your question is no.

However, in some cases, it may be possible to render part of an ASP.net page and then place the result into an ASP page.

I experimented with that a little bit last week using AJAX.

Here's what you can do.

Let's suppose that you have an ASP.net page with a form in it that you would like to render on an ASP page.

1) Create the ASP.net page with the form and wrap it in an ASP:Panel - give it an id: pnlForm 2) In your ASP.net codebehind, write the following code in Page_Load: pnlForm.RenderControl().

System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
pnlReport.RenderControl(htmlWriter);
Response.Write(stringWriter.ToString());

3) Add the following code snippet to the end of the codebehind:

// This snippet is neccessary to get ASP.net to render the report outsisde the page to write to an Excel spreadsheet.
public override void VerifyRenderingInServerForm(Control control)
{
    return;
}

4) Create a blank div in your classic ASP page - give it the ID formDiv.

5) On the classic ASP page, use jQuery.ajax to fetch the form and place it on the classic ASP page:

$.ajax({
 type: "GET",
 url: "myASPdotNetpage.aspx",
 success: function(response) { $('#formDiv').html(response); }
});

As you can imagine, this is not exactly how the framework is meant to be used, but if you really need to render some ASP.net and put it somewhere else (such as on an ASP page, or even a spreadsheet sometimes), you can at least capture the HTML.

like image 36
Vivian River Avatar answered Nov 14 '22 09:11

Vivian River