aspx:
<tr>
<td style="width:200px;height:19px">
</td>
<td style="width:550px;height:19px;vertical-align:top;" align=left valign=top>
<asp:PlaceHolder ID="MyControl" runat=server></asp:PlaceHolder>
</td>
</tr>
我现在在后台写的namespace JOL.Web
{
public partial class CompanyInfo : System.Web.UI.Page
{
string PageID = "0";
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Company"] == null)
JOL.Common.CommonFunction.MessageShow(Page, "请先等录系统!");
if (!Page.IsPostBack)
{
ViewState["ComName"] = "曹云森";
}
}
private void InitPage()
{
System.Web.UI.UserControl userControl;
if (Request.Params["PageID"] != null)
PageID = Request.Params["PageID"].ToString();
switch(PageID)
{
case "0":
UserControl = (JOL.Web.UserControl.PubJobInfo)LoadControl("~/UserControl/Company/PubJobInfo.ascx");
break; } }
}
加载一个用户控件
namespace JOL.Web.UserControl
{
public partial class PubJobInfo : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
} }
private void InitPage()
{
DataTable dt = new DataTable();
dt = JOL.Logic.JobCategoryLogic.GetJobCategory(true);
this.ddlCategory.DataSource = dt;
if (dt.Rows.Count > 0)
{
this.ddlCategory.DataSource = dt;
this.ddlCategory.DataValueField = "CategoryID";
this.ddlCategory.DataTextField = "CategoryTxt";
this.ddlCategory.DataBind();
}
this.ddlCategory.Items.Insert(0,new ListItem("请选择工作类别","0"));
this.ddlCategory.SelectedIndex = 0;
this.ddlJobType.Items.Insert(0, new ListItem("请选择工作类别", "0"));
this.ddlJobType.SelectedIndex = 0;
}
protected void btnSave_Click(object sender, EventArgs e)
{ }
protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
{ }
}
}
1。
UserControl = (JOL.Web.UserControl.PubJobInfo)LoadControl("~/UserControl/Company/PubJobInfo.ascx");
break;
,JOL.Web.UserControl.PubJobInfo没有联想功能2.错误 1 'JOL.Web.UserControl' is a 'namespace' but is used like a 'variable'
想请高手指点。
<tr>
<td style="width:200px;height:19px">
</td>
<td style="width:550px;height:19px;vertical-align:top;" align=left valign=top>
<asp:PlaceHolder ID="MyControl" runat=server></asp:PlaceHolder>
</td>
</tr>
我现在在后台写的namespace JOL.Web
{
public partial class CompanyInfo : System.Web.UI.Page
{
string PageID = "0";
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Company"] == null)
JOL.Common.CommonFunction.MessageShow(Page, "请先等录系统!");
if (!Page.IsPostBack)
{
ViewState["ComName"] = "曹云森";
}
}
private void InitPage()
{
System.Web.UI.UserControl userControl;
if (Request.Params["PageID"] != null)
PageID = Request.Params["PageID"].ToString();
switch(PageID)
{
case "0":
UserControl = (JOL.Web.UserControl.PubJobInfo)LoadControl("~/UserControl/Company/PubJobInfo.ascx");
break; } }
}
加载一个用户控件
namespace JOL.Web.UserControl
{
public partial class PubJobInfo : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
} }
private void InitPage()
{
DataTable dt = new DataTable();
dt = JOL.Logic.JobCategoryLogic.GetJobCategory(true);
this.ddlCategory.DataSource = dt;
if (dt.Rows.Count > 0)
{
this.ddlCategory.DataSource = dt;
this.ddlCategory.DataValueField = "CategoryID";
this.ddlCategory.DataTextField = "CategoryTxt";
this.ddlCategory.DataBind();
}
this.ddlCategory.Items.Insert(0,new ListItem("请选择工作类别","0"));
this.ddlCategory.SelectedIndex = 0;
this.ddlJobType.Items.Insert(0, new ListItem("请选择工作类别", "0"));
this.ddlJobType.SelectedIndex = 0;
}
protected void btnSave_Click(object sender, EventArgs e)
{ }
protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
{ }
}
}
1。
UserControl = (JOL.Web.UserControl.PubJobInfo)LoadControl("~/UserControl/Company/PubJobInfo.ascx");
break;
,JOL.Web.UserControl.PubJobInfo没有联想功能2.错误 1 'JOL.Web.UserControl' is a 'namespace' but is used like a 'variable'
想请高手指点。
就是没有放在"runat=server"中,
这样程序是执行不了的,
建议在页面中放一下Panal控件,
然后加入控件到Panal中
if (Session["AdminLogin"] != null)
{
MAdminLogin user = (MAdminLogin)Session["AdminLogin"];
string strQuanXian = user.sType ;
if (strQuanXian == "3")
{
Control c1 = LoadControl("/UserControls/cLeftNews.ascx"); Page.Controls.Add(c1);
this.Panel1.Controls.Add(c1); }
else
{
Control c1 = LoadControl("/UserControls/cLeft.ascx"); Page.Controls.Add(c1);
this.Panel1.Controls.Add(c1); }
}
这是我平时用的方法
需要执行里边的公开方法的时候 LoadControl出来的CONTROL再转换成你需要的类型