i have to work with a website project and need to use partial classes. But there is a problem with using.
TestPartial.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPartial.aspx.cs" Inherits="TestPartial" %>
<!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>
TestPartial.aspx.cs
using System;
public partial class TestPartial : System.Web.UI.Page
{
public int price = 200;
partial void Salary();
protected void Page_Load(object sender, EventArgs e)
{
Salary();
int newPrice = price;
}
}
TestPartial2.aspx.cs
using System;
public partial class TestPartial : System.Web.UI.Page
{
partial void Salary()
{
price = 400;
}
}
Error:
Error 1 The name 'Salary' does not exist in the current context
You need to declare the Test()
method on the calling side. Making it public
may be possible but does not seem a very good idea.
public partial class TestPartial : System.Web.UI.Page
{
partial void Test(); // add this line
protected void Page_Load(object sender, EventArgs e)
{
Test();
}
}
public partial class TestPartial : System.Web.UI.Page
{
partial void Test()
{
// executed from Page_Load
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.