View ASPX page in Web browser - asp.net

I have the following .aspx page, and I want to view it in web browsers such as IE or Google Chrome by opening it directly in those browsers:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
But somehow the browsers can't render it. In IE, the error is
Cannot view XML input using XSL style
sheet. Please correct the error and
then click the Refresh button, or try
again later. A name was started with
an invalid character. Error processing
resource 'file:/
<%# Page Language="C#"AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> -^*
What did I do wrong?

Remove or comment out the
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
line as a browser doesn't know what to do with it. This is normally interpreted by iis and not sent to the browser.

It won't actually work properly unless it is "served" by a web server of some sort.
If you are using Visual Studio, fire up the debugger, which by default will open IE, then grab the url from the location bar, and paste that into the browsers you want to check. Elsewise, mount the web site in IIS, and browse it that way.
Just opening the source file in a browser probably won't give you the result you are looking for.

Recent Visual Studios (at least 2010+) have a new feature called View in Browser which you can run on an .aspx file. Please note that, as per documentation, debugging breakpoints are not in effect even if debugging is enabled.
Right click the file in the Solution Explorer or the Editor and then select View In Browser (your default browser here).
Keyboard shortcut: Ctrl+Shift+W

Related

How do I find out where .aspx page is pulling its header?

I haven't worked with C# or ASP.NET before, but I'm trying to update some .aspx pages on a site. I'm noticing that there are also some updates that also need to be made in the <head> when I look at the source of the page, but I don't know how to determine where that header info is being pulled from to make that change.
Here are the two lines I'm seeing before it jumps into the HTML content:
<%# Page Language="vb" AutoEventWireup="false" Codebehind="DefaultLogin.aspx.vb" Inherits="TIMSSSSO.Web.DefaultLogin" %>
<%# Register TagPrefix="cc1" Namespace="Generic.Foundation.WebControls" Assembly="Generic.Foundation.WebControls" %>
Does any of this tell me where I should go to edit the header? Any guidance would be appreciated.

IE9 always runs in IE7 Compatibility mode

I have a simple page in asp.net vs2008, when run in IE 9, the compatibility view button is visible, when clicked, the web page always run in IE7 compatibility mode.
Why the page does not does run in IE8, when compatibility view button is clicked? Do we even have IE8 compatibility view?
Here is the html code:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Text="Testing"></asp:TextBox>
</div>
</form>
</body>
</html>
Try this:
Step 1:Turn off compatibility view and check.
Open internet explorer.
Click on Alt key on the keyboard. Now click on Tools in menu bar.
Select Compatibility View Settings.
Remove the check mark for Display all websites in Compatibility View
and close the Compatibility View Settings window.
Step 2: Reset internet explorer settings and check.
Fore more information refer : Microsoft link

ASP.NET adding a form to Master Page

So I've never really coded a website using ASP.NET. I'm trying to add a search form to a masterpage for my site. The problem is the whole body is wrapped in a form tag, which makes the functionality of my new form non-existant. I have a habbit of making bad situations worse by messing around with things I don't yet understand. So I thought I'd ask for your advice, my thoughts were:
Remove the runat="server" form tag completely.
Close it before my form and replace it at the end of my form.
Code within the button (which I later noticed you can't open.
Give up on ASP.NET and go back to PHP lol.
Hope you can help.
Thanks.
Master page will be like this
<%# Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="bodycontent" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
you can write the search page like this
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="Search.aspx.cs" Inherits="Search" %>
<asp:Content ID="Content1" ContentPlaceHolderID="bodycontent" Runat="Server">
//dnt include form tag here having runat = server
</asp:Content>
don't add content to the master page (you can, but don't for this example), add it to the content-page (.aspx). having the form on the master page means you don't have to manually add a form to content-pages; it's there automatically. (everything on the master page will be on the content-page.)
as masood is showing, search.aspx (the content-page) is using a master page, MasterPageFile="~/MasterPage.master". content goes in the content-tag.
I realised as I am used to hard coding in open source languages, that I was using HTML specific syntax, which was conflicting with the tag surounding the whole masterpage. In using the tools on the side I found my solution.
Thank you.
Well open Visual Studio Click File -> New -> Website -> Empty Web Site.
Create a MasterPage.master and add it to you project.
Example:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<html>
//.......
</html>
Create a SearchPage.aspx and bind it with your master page. Example:
< Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="MasterPage.aspx.cs" Inherits="MasterPage" Title="Untitled Page" %>

Master page gives error

I am using VS2008 for ASP.NET apps.
My Solution Explorer has hierarchy like this:
The start-up page, Default.aspx, displays a Login form. When I press Login button, another Page with the name, selectCompany, should open. selectCompany is a Web Content Form whose master page is Master1.Master. But it is not opening, instead I am getting this error:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'FlexStock.Forms.master1'.
Source Error:
Line 1: <%# Master Language="C#" AutoEventWireup="true" CodeBehind="~/Forms/selectCompany.aspx" Inherits="FlexStock.Forms.master1" %>
Line 2:
Line 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Source File: /Forms/master1.Master Line: 1
The first line of Master1.master is like this:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="master1.master.cs" Inherits="FlexStock.Forms.master1" %>
And the first line of Web Content Form, selectCompany.aspx, is like this:
<%# Page Title="" Language="C#" MasterPageFile="~/Forms/master1.Master" AutoEventWireup="true" CodeBehind="selectCompany.aspx.cs" Inherits="FlexStock.Forms.selectCompany" %>
I am not following where is the problem.
Make sure that the class-name stated in the Inhertis-part of your page-directive matches the name of the class in your code-behind file.
Master1.master:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="master1.master.cs" Inherits="FlexStock.Forms.master1" %>
Master1.Master.cs:
namespace FlexStock.Forms {
public class master1 {
/* ... */
Have you built your project w/o any errors/warning?
Error says that its unable to find code-behind class FlexStock.Forms.master1 so issue will be likely in master1.Master.cs or designer.cs - where you may have changed the namespace or class name w/o making the same change in markup. Or there is some compilation error and VS is unable to generate the assembly (or unable to put it in bin folder)
If you can see the bin folder in Explorer, but not in VS, try "Including" it in your project.
Maybe drag the folder into Solution Explorer, and then right-click it and Include it.

ASP.NET MasterPageFile causing error

I'm trying to use a master page in my website. I created a page and then created the master. I then added the tag MasterPageFile="~/master". I'm guessing that I need to do something to my main page, because I've now started getting the error:
The page contains markup that is not valid when attached to a master page
My main page is as follows:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MasterPageFile="~/my.master" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
I tried deleting the tag thinking that this might be the issue. Can anyone point me in the right direction?
You need to change your body to content sections. The master page works with contentplaceholders: your content pages need to provide the content for these placeholders. See the msdn page on this topic.
Quoted from that link above, your master page could contain the following:
<td><asp:contentplaceholder id="Main" runat="server" /></td>
Which the content page would fill by supplying the following
<% # Page Language="C#" MasterPageFile="~/Master.master" Title="Content Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
Main content.
</asp:Content>
Note that I included the main declaration at the top of the content page.
the pages inhering master page should have a <asp:Content as their root. this means no html tag no doctype etc.

Resources