Webform not allowed because it does not extend Class - c#

I have a very simple (currently) 1 page aspx website. It fails to compile with a message that I have not seen before. All other examples all seem to refer to master pages, which I do not have.
"Parser Error Message: 'Options.WebForm1' is not allowed here because it does not extend class 'System.Web.UI.Page'.
Source Error:
Line 1: <%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Options.WebForm1" %>
Line 2:
Line 3:
Here is the top of Default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="Options.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
And for Default.aspx.cs
namespace Options
{
public partial class _Default : Page
{

What is Options.WebForm1 in <%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Options.WebForm1" %>
It should look like this if you are using a namespace
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Options._Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="grdTest"></asp:GridView>
</div>
<asp:TextBox runat="server" Id ="callfmptxt"/>
</form>
</body>
</html>
Code Behind-
using System;
using System.Web.UI;
namespace Options
{
public partial class _Default : Page
{
private double callfmp = 0;
public double BlackScholes(string CallPutFlag, double S, double X, double T, double r, double v) { return 0.0;}
protected void allfmptxt_TextChanged(object sender, EventArgs e) { }
}
}

Related

Could not load the type 'BaseClass.aspx.cs'

I'm a beginner in asp.net (c#). I'm trying to develop an inheritance process. In my web application, I created a page called BaseClass.aspx. This is supposed to be the page from which I want to inherit all methods et properties. I create another page called DerivedClass.aspx. So I try to derive DerivedClass.aspx.cs from BaseClass.aspx.cs and I get this error:
Could not load the type BaseClass.aspx.cs
In DerivedClass.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeFileBaseClass="BaseClass.aspx.cs" CodeFile="DerivedClass.aspx.cs" CodeBehind="DerivedClass.aspx.cs" Inherits="TestHerit.DerivedClass" %>
In BaseClass.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="BaseClass.aspx.cs" Inherits="TestHerit.BaseClass" %>
I have tried all the solutions read on the net about this without solving the problem.
May anyone help me, please?
Yes,
Here is the content of BaseClass.aspx.cs:
namespace TestHerit
{
public partial class BaseClass : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
The content of BaseClass.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="BaseClass.aspx.cs"
Inherits="BaseClass" %>
<!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>Page sans titre</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
The content of DerivedClass.aspx.cs
namespace TestHerit
{
public partial class DerivedClass : BaseClass
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
The content of DerivedClass.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFileBaseClass="BaseClass.aspx.cs"
CodeFile="DerivedClass.aspx.cs" Inherits="DerivedClass" %>
<!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>Page sans titre</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
My web application starts with DerivedClass.aspx.
Thanks a lot.

Control is null when used nested master pages

I have a simple hierarchy of nested master pages.
However, in runtime, the master page controls (exemplified by label1) are always null.
If Default.aspx is changed to use Base.master directly, the master page controls will be correctly defined.
What is the cause for this behavior?
Base.master
<%# Master Language="C#" CodeFile="Base.master.cs" Inherits="BaseMaster" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server"></head>
<body>
<form runat="server">
<asp:Label runat="server" id="label1" Text="Label 1" />
<asp:ContentPlaceHolder runat="server" ID="MainContent" />
</form>
</body>
</html>
Base.master.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class BaseMaster : MasterPage
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
label1.Text = "Base"; // Causes NullReferenceException
}
}
Sub.master
<%# Master Language="C#" CodeFile="Sub.master.cs" Inherits="SubMaster" MasterPageFile="~/Base.master" CodeFileBaseClass="BaseMaster" %>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<asp:ContentPlaceHolder runat="server" ID="SubMainContent" />
</asp:Content>
Sub.master.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class SubMaster : BaseMaster
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
label1.Text = "Sub"; // Causes NullReferenceException
}
}
Default.aspx
<%# Page Language="C#" CodeFile="Default.aspx.cs" Inherits="DefaultPage" MasterPageFile="~/Sub.master" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="SubMainContent">
<h3>Default</h3>
</asp:Content>
Default.aspx.cs
using System;
using System.Web;
using System.Web.UI;
public partial class DefaultPage : Page
{
}

Affect another document on submit

I've got a upload function that pops up in a diffrent window, when i've submitted i want to send infomation back to the page that the upload window opened from.
Is that possible some way with ASP.net or C#?
Or would i have to use some javascript ? and how?
My 2 pages:
news.aspx - Contains a formview with my news. and a form with some inputs in.
This is where the link to open the upload page is...
uploader.aspx - Contains my upload controller and C# code to upload.
This should send a string from my C# code back to news.aspx and put it in one of my input fields or a label, not important.
uploader.aspx file:
<form id="form1" runat="server">
<div>
Vælg en fil at uploade:<br />
<asp:FileUpLoad id="FileUpLoad1" runat="server" />
<asp:Button id="UploadBtn" Text="Upload File" OnClick="UploadBtn_Click" runat="server" Width="105px" />
<br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
</form>
Behind Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class admin_Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void UploadBtn_Click(object sender, EventArgs e) {
Label1.Text = "Status: Uploader...";
if (FileUpLoad1.HasFile) {
FileUpLoad1.SaveAs(#"C:\Users\138409\Documents\Visual Studio 2010\Projects\Musicon\img\news\" + FileUpLoad1.FileName);
Label1.Text = "Status: " + FileUpLoad1.FileName + " er blevet uploadet";
} else {
Label1.Text = "Status: Filen blev ikke uploadet...";
}
}
}
Here is some Javascript code to create a popup window and, before the popup window closes, retrieve some information. (I will add a jQuery example in a bit)
//Site1.Master
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="PopupRedirect.Site1" %>
<!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="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
//Page1.aspx
<%# Page Title="" Language="C#" MasterPageFile="Site1.Master" AutoEventWireup="true" CodeBehind="Page1.aspx.cs" Inherits="PopupRedirect.Page1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
var message = "Hello World!";
var closeWindow = function(event) {
event.preventDefault();
window.close();
};
window.onload = function() {
document.getElementById('upload').addEventListener('click', closeWindow, false);
};
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<button id="upload">Upload File</button>
</asp:Content>
//UploadPage.aspx
<%# Page Title="" Language="C#" MasterPageFile="Site1.Master" AutoEventWireup="true" CodeBehind="UploadPage.aspx.cs" Inherits="PopupRedirect.UploadPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
var popupWindow;
var windowOptions = "menubar=yes,location=yes,resizable=no,scrollbars=no,status=yes,width=350,height=350";
var upload = function (event) {
event.preventDefault();
popupWindow = window.open("Page1.aspx", "Upload Page", windowOptions);
popupWindow.onbeforeunload = pageClose;
};
var pageLoad = function(event) {
document.getElementById('uploadLink').addEventListener('click', upload, false);
};
var pageClose = function (event) {
//put the code here that you want to execute when the window is done.
//like getting the value of some javascript variables
if(typeof (popupWindow.message) != "undefined") {
alert(popupWindow.message);
}
};
window.onload = pageLoad;
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<span>Welcome to this page! Click to upload.</span>
<button id="uploadLink">Upload</button>
</asp:Content>

What is the best method to retrieve the post value on another page in ASP.net 4.0

I search on internet but did not find any best solution, i found one way, where you need to code html tags like
<input type='text'> ... etc etc
and retrieve that value on another page as
Request.Form["name of input text field"];
W3Schools -ASP Forms and User Input
exists any better way to retrieve that post value??
ASP.NET WebForms has support for cross-page posting. Read http://msdn.microsoft.com/en-us/library/ms178139.aspx and http://msdn.microsoft.com/en-us/library/ms178140.aspx for more information.
Example:
WebForm1.aspx:
Note the asp:button has its PostBackUrl property set.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebFormApplication.WebForm1" EnableViewStateMac="false" %>
<!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"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="WebForm2.aspx" />
</div>
</form>
</body>
</html>
WebForm2.aspx:
Note that I've added the PreviousPageType directive here.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebFormApplication.WebForm2" %>
<%# PreviousPageType VirtualPath="WebForm1.aspx" %>
<!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>
This is page 2
<asp:Label Text="n/a" runat="server" ID="Label1" ></asp:Label>
</div>
</form>
</body>
</html>
WebForm2.aspx.cs: (Codebehind)
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(PreviousPage.IsCrossPagePostBack)
{
var tb = PreviousPage.FindControl("TextBox1") as TextBox;
Label1.Text = tb.Text;
}
}
}
The example you provide is useful for asp pages but I recommend to use QueryString collection for passing parameters between webforms in asp.net
Here is an example of how to use it :
using System;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
string v = Request.QueryString["Param1"];
if (v != null)
{
Response.Write("param is ");
Response.Write(v);
}
}
}
You could use Response.Redirect for concatenate the URL :
string _url = string.Format("../WebFormA.aspx?Param1={0}&Param2={1}", _param1, _param2);
Response.Redirect(_url);
Regards.

How in asp.net mvc create link that refer to some model.property?

I have strong-type view, I want to create link that refers to Model, which is strong-typed with that view, some property (e.g Model.property).
How can I do that?
I use net4.0.
when I write "> it do nothing.
Even visual studio don't recognize it when I write < a href="<%: and click ctrl+space it doesn't bring anything.
This is my view
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage<UrlParser.Models.Parse>" %>
<!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>Show</title>
</head>
<body>
<h1> Title: </h1>
<%: Model.title %>
<br />
<h1> Description: </h1>
<%: Model.description %>
<% if(!Model.video.Equals("")) { %>
<h2> Video:</h2>
<%: Model.video %>
<% } %>
</body>
</html>
I want my link refer to Model.video.
These is my controler:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UrlParser.Models;
namespace UrlParser.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(GetUrl getUrl)
{
// int i = 0;
Parse prs = new Parse(getUrl.url);
return View("Show", prs);
}
}
}
Not sure i follow you 100% but it looks like you might have your view defined without your model like:
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
And you will need something like this:
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MyViewModel>" %>
The key above is the MyViewModel which is you view model. This should have all your properties; MyViewModel.Video.
The following link was just missing the link text.
when you added something in between the and the it made the link visible.

Categories

Resources