How to Convert ContentPage to WebForm using Visual Studio - asp.net

I've created some Asp.net pages as ContentPages and I got a request to change these pages as pop-ups instead of opening in the contents of a master page.
Is there a way to convert ContentPages to WebForms using Visual Studio built-in functionality or I must adjust the design of each manually ?

Not sure if there is any inbuilt solution present (most probably NO) but one solution is to remove the master page section MasterPageFile="~/some_name.master from your page design section. Like,
Change this
<%# Page Language="C#" MasterPageFile="~/some_name.master" ...
To
<%# Page Language="C#" ...

Related

asp.net mvc render a webform as a partial in a razor view

I'm trying to use the asp.net webforms sitemap and menu control to build my asp.net mvc's sites navigation.
There are many tutorials about embedding razor views into webforms, but I want to go the otherway around. Embed a webform into a razor view.
Doing something like this looks eemi promising:
#Html.Partial("~/Views/Shared/test/menu.aspx")
Which presents an error:
Parser Error Message: 'System.Web.Mvc.ViewUserControl' is not allowed here because it does not extend class 'System.Web.Mvc.ViewPage'.
Is there a value for Inherits that would allow this to work?
Oh Duh, read the error message...
I changed the first line of the webform from this:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="menu.aspx.cs" Inherits="System.Web.Mvc.ViewUserControl" %>
to this:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="menu.aspx.cs" Inherits="System.Web.Mvc.ViewPage" %>
Then I ran into another issue about System.Web.Mvc.ViewPage being defined twice, so I deleted the *.designer.cs file and now its working.

Html helpers (from asp.net mvc) in webpages

Is it possible to use MVC Helpers in webpages (cshtml) ?
I'm trying out some controls from infragistics, and would like to use the html helper method to create the grid (avoiding some javascript) but I can't seem to get any intellisense.
No, I'm unsure if it should work?
Update: I want to use the following line:
#Html.Infragistics().Grid(....
inside my MyWebPagesPage.cshtml
Thanks for any help
Larsi
You should be able to, just add
#using infrajistics.namespace
You could also add the namespace to ur web.config namespaces section so that you don't have to add the #using in each view
There are no helper method that would render Infragistics controls. Please take a look at this page, it has detailed instructions of using Infragistics controls in MVC pages.
There are some limitations though. Infragistics doesn't have separate controls for MVC, they are simply making their asp.net controls available, but there's a drawback.
As long as you focus on areas of the controls that do not initiate post backs or rely on ViewState, you soon find many behaviors and functions that work perfectly in an ASP.NET MVC application.
Sample usage would be:
<%# Register Assembly="Infragistics.Web.Mvc" Namespace="Infragistics.Web.Mvc" TagPrefix="cc1" %>
<%# Register Assembly="Infragistics35.Web.v9.1, Version=9.1.20091.1015, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %>
<ig:WebDataGrid ID="wdg"
runat="server" Width="50%"
EnableViewState="false">
</ig:WebDataGrid>
No MVC helpers involved.

how to apply master page to pages in asp.net 2008

I am using .net 2008 for developing web application.
So I created a master page and some other pages. I want to apply master page to all other pages but I'm not getting it. Earlier i use .net2005 here there is option when we created a new page in application and check the master page option, but in .net2008 this option is not there so please tell me how to do it. I'm new to .net 2008 .
Please tell me
Thank you
If you want to manually set the masterpage for pages you have already created you can do the following: In the Page directive of your ASPX pages you set the masterpage like this:
<%# Page Language="C#" MasterPageFile="~/MasterPages/Master1.master" Title="Content Page"%>
Your MasterPage defines a few Content areas. You then should reuse those in your page and fill them with the local content.
When adding a new page the documentation says that when adding a Web Forms page you can select the Select master page check box, and then click Add. Then the Select a Master Page dialog box should appear.
You indicating that in your question
"when we created a new page in application and check the master page option"
If you are using a web application when you wan't to add a page with masterpage
you should add the page like this
Project ->
Add New Item ->
Web Form Using Master Page (instead of selecting Web Form)
Then you will have the option to select the masterpage
Use this code:
<%# Page Title="test" Language="VB" MasterPageFile="~/MasterPageName.master" AutoEventWireup="false" CodeFile="PageName.aspx.vb" Inherits="PageNameClass" %>
<asp:Content ID="Content1" ContentPlaceHolderID="maincontent" runat="Server">
//here you can add you page data start from form tag till end of form tag and remove everything else.
</asp:Content>

ASP.NET user control fails to render if registered with <%# Register Assembly="" (as opposed to Src="")

I'm trying to create a user control and reference it on an aspx page. It works, but only if I reference the individual control, like this:
<%# Register TagPrefix="schmapp" TagName="TestControl" Src="~/TestControl.ascx" %>
instead of referencing the whole namespace, like this:
<%# Register Assembly="UserControlTest" Namespace="UserControlTest" TagPrefix="app" %> <!-- doesn't work-->
I've done this many times yet it's been a while so I might be forgetting something basic. I refreshed my memory with a few tutorials and I think I'm doing the same steps.
I had this in the project I'm working on (.NET 3.5 under VS 2008) and I reproduced it step by step in a very basic project (.NET 4 under VS 2010) - I uploaded it for reference purposes.
I create a new asp.net web project, then Add -> New Item -> Web User Control, and then type some text into the ascx file (just to check if the control is being rendered). I then register the control and try to add it on the page. It works if it's referenced by Src attribute:
<schmapp:TestControl runat="server"/>
but not if the whole assembly is being referenced:
<app:TestControl runat="server" />
Now I can list the controls one by one but it's ugly and I don't want to accept defeat by something so simple, so I summon the might powers of teh internets to help.

Is it possible to include an asp (header) file on an asp.net page?

I have a classic asp website, onto which I am adding an asp.net (.aspx) page. Is it possible to include my existing asp header (header.asp) and footer (footer.asp) files on my aspx page?
I don't want to convert the page to a user control, because those pages include other asp pages with asp code on them.
Thanks
There's a rudimentary way of doing this described at Microsoft support. In a nutshell:
<%# Page Language="vb" AutoEventWireup="false"%>
<html>
<body>
<%
Response.WriteFile ("Yourfile.inc")
%>
</body>
</html>
One thing that may pose a problem for you is that this won't execute any classic asp code that's in your header/footer files, so wouldn't work for that scenario. If that's the case you may need to consider duplicating the content into an asp.net Master Page and maintaining two copies of the content.
As far as I am aware this is not possible as asp.net does not support vb script only full vb.net.
You could use an iframe to hold the classic asp includes, but then you run into problems where you have two separate sessions, classic asp and asp.net as they are not shared.
<div id="header"/>
<div id="footer"/>
$(document).ready(function()
{
$("#header").load("header.asp");
$("#footer").load("footer.asp");
}

Resources