Updating an ASP.NET website backend code - c#

It has been several years since I have really worked with ASP.NET C# but I have a client who needs to have a simple radio box added to a form which requires more then just editing the .ascx file.
I know that they have a custom .DLL file which I assume was compiled and then uploaded and contains the codebehind files?
The file has a code behind
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="PFA_Form.ascx.cs" Inherits="FLR.Controls.Input.PFA_Form" %>
Does this mean that if I edit the PFA_Form.ascx.cs I will have to do more then just upload that file via FTP?
As far as I know it is a Web Application Project. I have the files and solution, but Visual Studio is not connected to the web server in anyway.

If it's a ASP.net web site you can do it by just changing the code, it will be recompiled automatically. If it's an ASP.net web application you will have to compile and deploy it manually.

If you make changes to the code behind, you will have to recompile the server side code to create a new DLL.

If you only had to make changes to the ascx page, then sure, you could edit it. In this case, you need to make changes to the codebehind as well, and in ASP.NET that requires you to recompile and use the new DLL.

Depending on what you are deploying too, you need to recompile and get the new .DLL or if its a webapp you need to right click on the main project publish, and that will give you the new deploy package.

Related

Add page to asp.net website if source code/project solution is not available

I have been working on my clients site.
My client has only aspx and dll files now I want to add a new page to website, for testing purpose I have created a new project and uploaded its dll and aspx file but when I run the page it says.
Could not load type 'abc.index1122'
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="index1122.aspx.cs" Inherits="abc.index1122" %>
You need to get the uncompiled solution from your client. Start with that first.
If that code is not available, you have the more difficult road of grabbing a decompiler (I recommend Telerik's JustDecompile), and then reverse engineer a solution out of the DLLs. Only then can you start making additions and recompile / deploy the code to the target machine.

Add ascx.cs file to production web application

One of our clients has installed our web application into production.
We need to do a very quick patch to one of the aspx controls. I tried dropping the ascx and ascx.cs source files into the dir and unsurprisingly I got this error:
Exception type - HttpParseException - The base class includes the field 'foobar', but its type (UserControls_Controls_FOO) is not compatible with the type of control (ASP.usercontrols_controls_foo_ascx).
Yes, this approach is never a good idea, but is there anything I can do to the control to get it to run in the site instead of the version compiled into the DLL?
Doing a fresh install is not an option at this point.
no , you need to get it into compiled DLL and fresh deploy only then you can see the patch working
If you changed only ascx file you must update only it.
But if you updated ascx.cs you must Publish project and replace old bin directory with new one.
Also you can transform site to set of dynamically compiled pages, but it is hardcore old way and bad idea nowadays.

Visual Studio 2010 Disable Designer Code Generation for particular ascx controls

I am currently developing a website for a Berkeley Club in Visual Studio 2010 Prof. Ed. using Asp.net and Dotnetnuke v6. This will be my second time encountering this specific problem/hassle. I created a new control (ascx file) and have been working on it some. I wanted to add the Dotnetnuke htmleditor since its sick so added the required code. Namely...
<%# Register TagPrefix="dnn" TagName="TextEditor" Src="~/controls/TextEditor.ascx"%>
<dnn:TextEditor ID="EmailContent" runat="server" Height="400px" Width="100%" />
I also had to change the ascs.designer.cs file so that instead of reading
protected global::System.Web.UI.UserControl EmailContent;
it read like
protected global::DotNetNuke.UI.UserControls.TextEditor EmailContent;
This makes it use the DNN TextEditor which is what I want. The problem is that whenever VS uses the designer to autogenerate code it overwrites the bottom line with the top line. This means every time I change the ascx file I have to change the designer again. This has gotten annoying, but I have not been able to find a way to fix it. Any ideas on how to disable the VS designer for specific controls or for segments of code in a autogenerated designer file?
Put the EmailContent declaration in the ascx.cs file, and remove it from the ascx.designer.cs file. This will prevent the designer from messing up the type.
This goes to ascx.cs:
protected global::DotNetNuke.UI.UserControls.TextEditor EmailContent;
The problem is that Visual Studio is interpreting the path ~/ to mean the root of your project, instead of the root of the DotNetNuke website (how it will resolve at runtime).
If your module project that you're working on is located in a DotNetNuke site which is hosted in your local IIS, you can setup the project to know where it's actual root is. In the project's properties, go to the Web tab and make sure that it's setup for IIS. The project URL should be the URL to your module (e.g. http://mysite.dnndev.me/DesktopModules/MyModule) and then check the "Override application root URL" checkbox and enter the website's root there (e.g. http://mysite.dnndev.me). This should allow Visual Studio to realize where ~/controls/TextEditor.ascx points, and find the right type.
That said, this works for us about 90% of the time, but we've had some projects where this doesn't work for whatever reason, and then we resort to #mika's answer of moving the declaration from the designer file to the codebehind file.

Parser Error on all new aspx pages in IIS7

I have a web site where any new aspx pages throws a "Parser Error". It has existing pages, and I can change the html or the c# code in it, and the change will appear in the web page in the browser.
The error page gives a message of "Could not load type classname". I've tried adding several different pages in Visual Studio, and copying the pages to IIS, so the syntax of the page should be fine.
I;ve also made sure that the "Inherits" attribute has the correct class and the class exists. I'm completely stuck.
Have a look at the Directive at the top of the page. Does it have a CodeBehind attibute? If so change it to CodeFile, and try the page in the browser again.
If that doesn't work, compare the top part of a non-working page and a working page. Would be a little easier if you could post the top parts of the page here.
One thing that popped to mind immediately is to make sure that the target version of the .NET Framework for your web site is the same as the one specified for the application pool in IIS in which the site is running.
Right-click on the web site in Visual Studio and check the "Target framework" setting. Make sure this matches the ".Net Framework version" setting in IIS.
Are you using any usercontrols? Is your project set up as a web Application project or website?
If you are developing a web application project and you copy a new file or add a page without using the add new by right clicking you may have some page files that lack their designer files.
If that is the case then I suggest right clicking any page missing the designer file and click "Convert To Application" Then rebuild your solution

UserControls in Class Library

I am converting a 1.1 project to 2.0 and am having an issue with some User Controls.
In the original project, there was a class library project and the website project. In the class library project, there was a folder called UserControls and in this were several ascx files and their code behind files.
I'd like to keep the same structure so I bring in these user controls into my new solution in a separate class library project. I changed it from being a full class to a partial class and changed the CodeBehind to CodeFile of the page.
In the old user control, all the web controls in the User control were listed like follows
protected System.Web.UI.WebControls.DropDownList _findModeList;
etc.
I thought with it being .net 2 and using the CodeFile attribute instead, I may not need to do this but it doesn't compile when I omit it.
However, when I include it, it does compile, but I get "Object reference not set to an instance of an object." error when trying to use _findModeList in the code file.
Is it possible to put User Controls in a class library in .net 2.0 up?
Not really. The .ASCX file should be included in each Web Application project that uses it. To avoid duplicates you can store the UserControl in your Class Library's folder and use the "Add As Link" feature of Visual Studio.
Select "Add Existing Item" in your Web Application's context menu, select the user control and, instead of clicking the "Add" button, click the arrow in that button and select "Add As Link".
Are you working with a Web Application Project? Or a Web Site? It's confusing, I know...
If you are working with a WAP, use CodeFile and let ASP.NET generate the .designer.cs files for you. Do not declare the objects from your .acsx. You are declaring a new/different DropDownList when you explicitly declare _findModeList in the .cs file referenced by CodeFile. That is why you get the null reference... it has not been initialized. If you don't have a .designer file, right-click on the .ascx in Solution Explorer and click "Convert to Web Application".
If you are working with a Site rather than a WAP, use the CodeBehind attribute. It will continue to work like in ASP.NET 1.1 and compile on the fly.
To get a control to live entirely in a DLL... use "custom controls" rather than user controls. Again, confusing.
Actually you can try create new Web Application Project not Create new Web Site , because between these two are different project.
After you create Web Application just create your User Control (.ascx). After that you can try Rebuild your Web Application. After finished you can browse to your bin directory , there should be dll for your web application. Now you can use this dll in another website/web application project. Just add reference to this dll.
Have you tried changing/adding the Inherits attribute in the <%# Control %> tag?
<%# Control Language="C#" CodeBehind="<PathToTheFile>" Inherits="namespace.and.classname" %>

Categories

Resources