i am having lots of trouble getting started today... i keep getting
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 'Webapp5.landing'.
Source Error:
Line 1: <%# Page Language="C#" AutoEventWireup="true" CodeBehind="landing.aspx.cs" Inherits="Webapp5.landing" %>
Line 2:
Line 3: <!DOCTYPE html>
here is my code behind....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Webapp5
{
public partial class landing : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
and here is my page...
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="landing.aspx.cs" Inherits="Webapp5.landing" %>
<!DOCTYPE html>
<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>
i know i am missing something easy here.... but i just cant get seem to get this working?
any ideas on how to get this page to run?
Related
When I add a webform to my page, I keep getting the error below:
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 'WebApplication9.WebForm11'.
If I remove the Inherits portion it will run. It will also run if I add the inherits portion on one particular reference: Inherits="WebApplication9.GaugePro"
But if I do Inherits on anything else it will error out. Any idea what I did wrong. This just started happening....
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm11.aspx.cs" Inherits="WebApplication9.WebForm11" %>
<!DOCTYPE html>
<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>
Just try changing the CodeBehind to CodeFile as follows:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="WebForm11.aspx.cs" Inherits="WebApplication9.WebForm11" %>
It may occurs in another case also, when you create web application project, then the directive should be:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm11.aspx.cs" Inherits="WebApplication9.WebForm11" %>
For the website project, the first one should work fine.
The small profile picture in top right corner of the page is part of master page (asp:Image) and will be display on Page_load event.
In the content page which will be used to update the profile picture, after save button click event fired, how do I update the picture on master page, right now only the big picture of content was updated (because I put the code to update it at the end of Save_button click event). What the the idea here and what steps I should follow?
First use the MasterType property in the child page (MasterPage is the class name):
<%# Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="Child1.aspx.cs"
Inherits="Child1" Title="Untitled Page" %>
<%# MasterType TypeName="MasterPage" %>
Then, in the MasterPage, make public any property or field you want the child pages to have access to.
The properties/fields should show up in intellisense in the child pages.
Here is the full code to a MasterPage and how to make an element public:
MasterPage.Master:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html>
<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">
<asp:image id="_MyImage" runat="server"></asp:image>
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
MasterPage.Master.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
public Image MyImage
{
get { return _MyImage; }
}
}
Try raising an event from the User Control and have the Master Page handle the event.
Here is an example:
http://snippets.surfthru.com/post/ASPNET-Raise-Event-on-Parent-Page-from-User-Control
I'm new to ASP.NET and C#, I've primarily worked with Java. I want to dynamically add nodes to a tree view. I've followed a few tutorials but whenever I implement them they do not appear to work. I keep getting an error: "The name 'MyTreeView' does not exist in the current context".
Here's the C# code:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace LocalTest
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
MyTreeView.Nodes.Add(new TreeNode("Node1"));
MyTreeView.Nodes[0].ChildNodes.Add(new TreeNode("ChildNode"));
}
}
}
}
And the HTML/ASP:
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="MyTreeView" Runat="server">
</asp:TreeView>
</div>
</form>
</body>
</html>
"MyTreeView" is the ID of the treeview contained in the Default.aspx file.
The few tutorials I have followed seem to access the treeview directly with its ID as seen above which makes very little sense to me. For instance, if I were to do this in Android I would have to use the findViewById and establish a link between the XML and the Object.
Does anyone have any suggestions? I've bumbled around this site for a bit and I'veonly found similar issues but I cannot get a clear answer.
Thank you.
Looking at the code above, you are using what's known as ASP.Net WebForms where there are "server side" controls (e.g. <asp:TreeView ID="MyTreeView" Runat="server">)
The "page" (html aspx) needs to somehow "wire itself" to the code (c# file). It will need a "server-side" directive like so:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebFormsApplication.WebForm1" %>
<!DOCTYPE html>
//...the rest of the html goes here plus web controls, etc.
At which point, you can see stuff like Inherits="WebFormsApplication.WebForm1" that maps to the Class:
namespace WebFormsApplication
{
public partial class WebForm1 : System.Web.UI.Page
....
found in the WebForm1.aspx.cs file, also in the directive CodeBehind="WebForm1.aspx.cs"
So voila :)
establish a link between the XML and the Object.
Hth...
You do not have TreeView control in default.aspx. It is in .html file and default.aspx.cs can not see TreeView control.
It seems you are missing Page directive in your asp.net page
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
I am just learning how to use TCP client server relationships. I have been looking for hours and hours but I do not see any way that a Client can get input from the user and then the client sent a byte[] array to the server and have it do anything but compare strings, is there some way that I can have it call a method with this input? or am I missing something?
I have heard of something called serialization, though there seem to be several ways to use it, can someone point me in the right direction if this is correct?
Thanks for any reply
For a basic .NET website, I like to use the page methods for a quick easy way to make client to server calls. Consider the following aspx page and its code behind. You can expose public static server methods to javascript by adding the [WebMethod] attribute. Then you can call the function from javascript using PageMethods.NameOfFunction(). Just make sure you have a scriptmanager on the aspx page with the EnablePageMethods property set to "true".
Default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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>
<script type="text/javascript">
function init() {
var str = "bytes";
var data = [];
for (var i = 0; i < str.length; ++i)
{
data.push(str.charCodeAt(i));
data.push(0);
}
PageMethods.DoSomething(data);
}
</script>
</head>
<body onload="init();">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptMan" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.Web.Services;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static void DoSomething(byte[] data)
{
//Do something with data from javascript
}
}
My page contains a user control and inherits a master page. Both have a button. I have put it in a form tag. I am just trying to do an event bubbling from master page as well as user control. Now it doesn't load because of multiple form tags error. How to do it?
Masterpage :
<%# Master Language="C#" AutoEventWireup="True" CodeBehind="SampleSite.master.cs" Inherits="EventBubbling.SampleSite" %>
<!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>
<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:Button ID="Button1" runat="server" Text="MasterPageButton" />
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
User control :
<%# Control Language="C#" AutoEventWireup="True" CodeBehind="SampleUserControl.ascx.cs"
Inherits="EventBubbling.Controls.SampleUserControl" EnableViewState="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 id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnUC" runat="server" OnClick="btnUC_Click" Text="UserControlButton" />
</div>
</form>
</body>
</html>
User control.cs page :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace EventBubbling.Controls
{
public partial class SampleUserControl : System.Web.UI.UserControl
{
public event EventHandler buttonClick;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUC_Click(object sender, EventArgs e)
{
buttonClick(sender, e);
}
}
}
Main Page :
<%# Page Language="C#" AutoEventWireup="True" MasterPageFile="~/SampleSite.Master"
CodeBehind="Default.aspx.cs" Inherits="EventBubbling._Default" %>
<%# Register Src="~/Controls/SampleUserControl.ascx" TagPrefix="uc" TagName="SampleUserControl" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<div>
<uc:SampleUserControl ID="UC1" runat="server" />
</div>
</asp:Content>
.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace EventBubbling
{
public partial class _Default : System.Web.UI.Page
{
Button btn = new Button();
protected void Page_Load(object sender, EventArgs e)
{
UC1.buttonClick += new EventHandler(UC1_buttonClick);
btn = this.Master.FindControl("Button1") as Button;
btn.Click += new EventHandler(btn_Click);
}
void btn_Click(object sender, EventArgs e)
{
Response.Write("EventBubbling from MasterPage");
}
void UC1_buttonClick(object sender, EventArgs e)
{
Response.Write("EventBubbling from User control");
}
}
}
My goal is to learn event bubbling but I get some basic error with this code I posted.
your user control should not have a < form> tag, this is taken care of by the MasterPage all pages / controls are then rendered inside this master control < form> tag.
If you want to have your user control with its own form you will have to change to a different MasterPage and to be honest I am not sure how that would even work.
Keep Id of form different every where you are using form tag.
every where its <form id="form1" runat="server">.
Make it as Id=1 , Id=2 ,etc.
In master page keep form Id=1 , in user control page make it as 2 and in main aspx make it as 3.
Or Remove form tag from usercontrol page.
Since you have placed controls in master page, you need to keep the <form> tag thereon.
The error message: A page can have only one server-side Form tag. should actually be taken as: A page can have only one visible server-side Form tag.
if you want you can have more than one form tags.
Read here one Great tricks of Asp.net: http://blogs.msdn.com/b/kaevans/archive/2005/10/19/482778.aspx . Definitely not of much practical use.
Else, You need to correct the Markup of your userControl. Remove tags like: head, html, form.
Your final markup of UserControl will be:
<%# Control Language="C#" AutoEventWireup="True" CodeBehind="SampleUserControl.ascx.cs"
Inherits="EventBubbling.Controls.SampleUserControl" EnableViewState="false" %>
<div>
<asp:Button ID="btnUC" runat="server" OnClick="btnUC_Click" Text="UserControlButton" />
</div>
I hope you get the idea what all needs to be removed.
All such pages or usercontrols that are going to be a part of this master page must not contain any <form> tag.