VB webform in IronPython asp.net website - asp.net

I tried to bring a previously done webform made in vb.net to an IronPython asp.net website with no luck. After seeing it didnt work, I tried to write the simplest codebehind vb.net webform to see if there was a problem with vb.net in an IronPython website and I got the following usual error
"be sure that the defined class in this file matchs with the one in the attribute inherits and that it extends the right base page (page or control)" (sorry if the translation isnt the most accurate I get that message in spanish)
but if I create a vb.net webform in the same website, with the sourcecode in the same file (with the vb.net code between script runat="server" tags in the same page) I get no problem.
Do I have to configure something for both kind of sourcecode languages to run in such way in the same IronPython website, like configuring something in the webconfig file or is there some compatibility issue for doing that which can't be resolved?

The code between <script /> tags is compiled dynamically when the page is first run. This enables you to mix languages. However, the classes in your code-behind files are statically compiled into an assembly by VS.NET ... and a VS.NET project can only support one language at a time.
One solution is to put your VB.NET code-behinds in a separate assembly. For example:
Add a new VB Class Library project to your existing solution
Add a reference to System.Web
Create your VB.NET code-behinds. They should be normal classes inheriting from System.Web.UI.Page.
In your ASP.NET website project, add a reference to the new project
Edit the # Page directives in your *.aspx files to inherit the classes in the new project
e.g. <%# Page Inherits="YourNewVBClassLibraryProject.MyVBCodeBehinds" ... /> where the Inherits attribute contains the relevant namespace-qualified class name

Thanks for the reply Serilla. Your information was interesting but I simply solved it by creating the app_folder and adding the vb files there. Do you think I could have some future problem for doing so?
The problem with the vb files was when these lines in the web.config were enabled for Ironpython to work
<pages compilationMode="Auto" pageParserFilterType="Microsoft.Web.Scripting.UI.NoCompileCodePageParserFilter" pageBaseType="Microsoft.Web.Scripting.UI.ScriptPage" userControlBaseType="Microsoft.Web.Scripting.UI.ScriptUserControl">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
when I removed them, vb code behind files worked but ironpython didnt. When the lines were there, Ironpython code behind files worked but vb ones didnt

Related

VS2015 - VB/ASP.NET Build fake error: "Type 'XYZ' is not defined" in UserControl code-behind

Ok guys, this one is not easy...
For the story, I got a old 3.5 ASP.NET/VB.NET website project (ASPX) build on VS2012 that I've upgraded to 4.5 to run well on VS2015.
I'm also trying to remove all the compilations errors that it got, even if the website was working under them (VB.NET is weird...)
During this operation, I've got some unchanged codes that worked well before but they don't let me run anymore.
So, here is the build problem:
I've got a UserControl (private/UserControls/Fiche/OngletAccueil.ascx), used in a page (private/fiche.aspx), that need some values from the MasterPage (private/MasterPage.master).
They all use the same namespace Vita, here are some excerpts to understand:
The MasterPage:
Namespace Vita
Partial Public Class private_MasterPage
Inherits System.Web.UI.MasterPage
Public _debug As Integer = HttpContext.Current.Request.Params("debug")
Public ReadOnly Property ModeDebug As Integer
Get
Return _debug
End Get
End Property
...
The UserControl:
Namespace Vita
Public Class private_UserControls_Fiche_OngletAccueil
Inherits System.Web.UI.UserControl
Public ReadOnly Property modeDebug As Integer
Get
Return DirectCast(Me.Page.Master, private_MasterPage).ModeDebug
End Get
End Property
...
The ASPX page:
<%# Page Async="true" Title="" Language="VB" MasterPageFile="~/private/MasterPage.master" AutoEventWireup="false" CodeFile="fiche.aspx.vb" Inherits="Vita.public_fiche" %>
<%# Register TagPrefix="Tools" TagName="OngletAccueil" Src="UserControls/Fiche/OngletAccueil.ascx" %>
...
With that, I got a compilation error about the MasterPage class type in the UserControl:
Type 'private_MasterPage' is not defined.on \private\UserControls\Fiche\OngletAccueil.ascx.vb
I don't even understand why it don't run the IISexpress when it was ok on previous framework...
I show you the code to make you understand that the code is not really the problem: it seems that the problem come from intelliSense or from the compilation temp files, like if the MasterPage class can't be seen (scope access) by the UserControl because they are not in the same temp assembly.
Before, I've got the same problem with a userControl used into another userControl (which files are saved in exactly the same folder...), but I was able to trick the compilator with a web.config setting, it seems to work:
<pages>
<controls>
<add tagPrefix="Tools" src="~/private/UserControls/Fiche/PosteUser.ascx" tagName="PosteUser" />
<add tagPrefix="Tools" src="~/private/UserControls/Fiche/NotesDeFrais.ascx" tagName="NotesDeFrais" />
<add tagPrefix="Tools" src="~/private/UserControls/Fiche/Evals_CollaborateursInternes.ascx" tagName="EvalsCollaborateursInternes" />
</controls>
</pages>
But here, the MasterPage is not a control, it's a page, I can't use the same trick...
Thx for help guys, I've already spent a lot of time on it and I did analyzed a bunch of Q&A & MSDN docs before post it here, on this you're my last hope :'(
Here some last & useful infomation on the web.config:
<supportedRuntime version="v4.0"/>
...
<compilation debug="true" batch="false" strict="false" explicit="true" targetFramework="4.5">
...
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
...
Ok guys, I got it, by changing PC...
I think the problem come from compilating the project on different versions of VS.
I did only one compilation of my project on 2012 and then the compilation on 2015 made this unbreakable error...
So even if you purge some temp folders like AppData\Local\Temp\Temporary ASP.NET Files, AppData\Local\Temp\VWDWebCache or .vs\project\v14\.suo, it's not enough.
After some more debug on others things that appeared, I can now compile with 0 errors and publish also after bit more debug. Now I'm on some other problems on runtime, it's still not fully working like before but it's getting closer ;)
UPDATE
What I did before worked for the compilation but it didn't solved the runtime (the bug came back on runtime as InvalidCastException).
To solve the runtime, I just checked the Build/Publish option "use fixed naming and single page assemblies" and it solved my case :)
Unckeck also the build (and publish) option "Allow this precompiled site to be updatable"
Here some useful links: https://msdn.microsoft.com/en-us/library/hh475319(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/aa479044.aspx
http://forums.asp.net/t/960707.aspx

Web.config add namespace not applied at file level

I am referencing a class library in a web application project (both in same solution). Within the web pages of the web application, if I do this:
If MyValidation.CorrectEmailFormat(email) Then ...
...Visual Studio 2013 underlines the method, and suggests I import MyCompany.EmailMethods at the top of the page. If I do the Import, the page compiles and the method works okay.
However, because these methods are used extensively across the application, I don't want to add them at page level every time. So I headed for web.config, and did this:
<pages>
<namespaces>
<add namespace="MyCompany.EmailMethods" />
</namespaces>
</pages>
However, VS is still prompting me to perform the Import at the top of every page, and the method is not recognised in the page without doing this. What I am doing wrong please? I assumed from MSDN and other sources this was the correct way to achieve this.
Web application is ASP.Net web pages (4.6).
The reference must be added to the Imported Namespace as described in the following SO post
add-a-namespace-reference-to-all-web-application-web-pages-in-a-different-project
It must be added in the project properties page at the bottom part titled Imported Namespaces
The <pages> directive applies to ASPX files only.
You need to use the equivalent directive for Razor:
<system.web.webPages.razor>
<pages>
<namespaces>
<add namespace="MyCompany.EmailMethods" />

Adding System.windows.Forms reference into asp.net website

I have a asp.net application where i use System.Windows.Forms namespace reference to use web browser control.the application runs fine on local system but after hosting it shows error.
How do i embed the dll for to use in the web application.
Answering a 3 1/2 year old question is pretty weird...
I. In your web.config, add a reference to Windows.Forms
<system.web>
<compilation>
<assemblies>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<system.web>
This only works if the referenced DLL is in the GAC. If it is not:
Create a /Bin folder in your website root.
Copy your DLL there.
Do not add a reference in web.config.
II. In your module/class, import Windows.Forms (VB: Imports / C#: using)
Imports System.Windows.Forms
You can now use the web browser control. It's a bit tricky, though.
Possible uses include: generating screenshots, AJAX crawling (#! >> _escaped_fragment_) etc
System.Windows.Forms contains classes for displaying things on the computer that the code is running on. When you are testing on your PC, it works because you run the browser on the same machine as your development server.
When running on a real server, anything in System.Windows.Forms would be displayed on the server - not on the user's PC. (Besides it would be displayed on a hidden desktop in the server's service session).
You shouldn't mix webforms and windows forms. Whatever you want to do - there is another way that works, that doesn't involve winforms.
Don't use System.Windows.Forms in webb applications
As previously mentioned, you cannot use WinForms controls with ASP.NET.
Use an iframe to show whatever page you're trying to display in the webbrowser control: http://www.w3schools.com/tags/tag_iframe.asp
yes, you can do it,just copy the
system.window.form
dll into your web Bin Folder
everything will work fine.

How to load webusercontrol from classlibrary

I have a classlibrary. This library contains widget.ascx control. How to load this webusercontrol from web. I know "LoadControl". But this not applicable.
How can i load web usercontrol from library?
2009.09.24
My main goal is i'm creating addon based web application. Every addon will be widget of web application.
I need dynamically load web usercontrol from library
You need to add a reference of the library to your web project.
Then instantiate it as you would with any other control, either programatically or in an #Register directive.
Kindness,
Dan
In addition to obviously adding the DLL to your project references, you also need to register the control. You can do this on each page that will use the control, but I usually prefer to do it in web.config. As a quick example, here's the line I used to register the Infragistics UltraWebGrid control in my app.
<pages>
<controls>
<add tagPrefix="ig" namespace="Infragistics.WebUI.UltraWebGrid" assembly="Infragistics35.WebUI.UltraWebGrid.v8.2, Version=8.2.20082.1000, Culture=neutral, PublicKeyToken=7DD5C3163F2CD0CB"/>
</controls>
</pages>
TagPrefix works kind of like an in-page namespace, so if I had a bunch of controls I was importing from one DLL, they'd probably all have the same TagPrefix. In the page, I'd simply reference my control as follows:
<ig:UltraWebGrid runat="server" SetSomeOtherPropertiesToo="blah" />
I am not sure how the .ascx file is added to your class library. Normally user controls are loaded using LoadControl which requires an existing file. In case the user control is compiled as embedded resource in your class library you could use GetManifestResourceStream() to read the user controls' contents and then ParseControl to create a control from the string read using GetManifestResourceStream.

How to fix the HTML Intellisense in ASP.NET AJAX Controls or Pages

I'm using ASP.NET AJAX. I create a .aspx page that is based on a .master file. I add the , , control into the content page, and suddenly the markup intellisense no longer works for these controls, or for any controls nested within them.
Is this a bug? Can I fix this?
The fix for the intellisense issue will be in VS 2005 SP1.
In the meantime there are two workarounds that you can use to fix it immediately:
1) Keep the .master file open within the Visual Studio IDE when working on the .aspx content page. It turns out the intellisense engine only runs into issues if the .master file is closed. As long as it is open within the same IDE, it resolves the assemblies just fine and will give you full intellisense
2) Go into your web.config file and change the tag-prefix naming for the ASP.NET AJAX controls to something other than . For example, instead of:
<controls>
<add tagPrefix="asp" namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Extensions" />
<add tagPrefix="asp" namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Extensions" />
</controls>
change them to something like this:
<controls>
<add tagPrefix="ajax" namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Extensions" />
<add tagPrefix="ajax" namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Extensions" />
</controls>
You'd then want to update your tag prefixes in your .aspx page to use this new tag prefix.
Either of these approaches will solve the problem and deliver full intellisense. The issue should then be resolved completely with VS 2005 SP1.

Resources