전체 사이트에 대해 한 페이지 밖에없는 페이지가 있습니다.마스터 페이지에서 유일한 페이지의 공용 페이지 변수에 어떻게 액세스합니까?
using System;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class CMSPageViewer : System.Web.UI.Page
{
public int myPageID;
protected void Page_PreInit(object sender, EventArgs e)
{
// Get stuff from the database
myPageID = 1;
// Set the Page.MasterPageFile
}
protected void Page_Load(object sender, EventArgs e)
{
// Fill in the page contents
// This looks for and fills in asp:ContentPlaceHolder controls based on ID
}
}
그리고 마스터 페이지 :
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Standard_Page : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
int myID = (this.Page as CMSPageViewer).myPageID;
}
}
사용 된 마스터 페이지에서 ID에 어떻게 액세스합니까?
페이지 캐스팅이 작동하지 않는 것 같습니다. 다음과 같은 오류가 발생합니다 :
Compiler Error Message: CS0246: The type or namespace name 'CMSPageViewer' could not be found (are you missing a using directive or an assembly reference?)
CMSPageViewer는 App_Code 또는 일부 클래스 라이브러리에서 정의 된 "실제"클래스 (부분 .aspx가 아닌 부분) 여야합니다. –